Eclipse 设置以能够编译 snmp 代理

问题描述

我使用 net-snmp 编写了一个 SNMP 代理,我将其编译为 C++ 应用程序,因为它使用 Rapidjson 库从 json 文件中读取一些设置。

当我使用以下 Makefile 在带有 Debian 10 的 Linux 机器上编译它时,它编译没有错误:

CC = g++

SRC = $(shell find . -name '*.c')
OBJS = $(SRC:.c=.o)
TARGET = agent_daemon

CFLAGS = -I. `net-snmp-config --cflags`

BUILDLIBS = `net-snmp-config --libs`

BUILDAGENTLIBS = `net-snmp-config --agent-libs`

DLFLAGS = -fPIC -shared

all: $(TARGET)

$(TARGET): $(OBJS)
        $(CC) -o $(TARGET) $(OBJS) $(BUILDAGENTLIBS)

clean:
        rm -Rf $(OBJS) $(TARGET)

现在我需要从 Eclipse 编译它,但是创建一个 Eclipse 项目,其中 Makefile 由 Eclipse 定义,而不是使用上面的 Makefile。

编译时出现如下错误:

Invoking: GCC C Compiler
gcc -std=c++17 -I../inc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/MyTable/readConfigFile.d"
-MT"src/MyTable/readConfigFile.o" -o "src/MyTable/readConfigFile.o" "../src/MyTable/readConfigFile.c"
In file included from /usr/include/rapidjson/stream.h:15,from /usr/include/rapidjson/filereadstream.h:18,from ../src/MyTestFFVTTable/readAlarmsFFVTConfigFile.c:14:
/usr/include/rapidjson/rapidjson.h:39:10: fatal error: cstdlib: No such file or directory
 #include <cstdlib>  // malloc(),realloc(),free(),size_t
          ^~~~~~~~~
compilation terminated.
make: *** [src/MyTable/subdir.mk:35: src/MyTable/readConfigFile.o] Error 1
"make all" terminated with exit code 2. Build might be incomplete.

我在 Eclipse 中的配置是

Project --> Properties --> C/C++ Build --> Settings --> GCC C++ Compiler
    Command:      C++
    All options:  -std=c++17 `net-snmp-config-cflags` -I. -I../inc -I/usr/include/c++/8/tr1/cstdlib -I/usr/include -O0 -g3 -ftest-coverage -fprofile-arcs -Wall -c -fmessage-length=0


Project --> Properties --> C/C++ Build --> Settings --> GCC C++ Linker
    Command:      C++
    All options:  -ftest-coverage -fprofile-arcs -pthread

我使用“find”命令搜索了 cstdlib 在磁盘上的位置

$ sudo find / -iname "*cstdlib*"
/usr/include/boost/compatibility/cpp_c_headers/cstdlib
/usr/include/boost/cstdlib.hpp
/usr/include/c++/8/cstdlib
/usr/include/c++/8/tr1/cstdlib

并且我做了四次测试,在“Project -> Properties -> C/C++ Build -> Settings -> GCC C++ Compiler”中加入路径(每次一个不同):

  1. 测试 1:-I /usr/include/boost/compatibility/cpp_c_headers/cstdlib
  2. 测试 2:-I /usr/include/boost
  3. 测试 3:-I /usr/include/c++/8/cstdlib
  4. 测试 4:-I /usr/include/c++/8/tr1/cstdlib

但在所有情况下,我都会遇到相同的错误。

感谢有关我必须在 Eclipse 中设置的正确选项的任何帮助,以免出现与 cstdlib 相关的错误并能够 使用相同的选项编译代理,就像我使用上面指示的 Makefile 手动编译一样。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)