致命错误:网络通讯协议。h:没有这样的文件或目录。

时间:2021-12-03 18:56:16

I'm expecting a lot of difficulties to make my program working with the library libmodbus on Linux.

我希望我的程序在Linux上与图书馆libmodbus一起工作有很多困难。

I've installed libmodbus with the command sudo make install and after make but the problem is when I want to link the library in my C program.

我已经安装了libmodbus,命令sudo进行安装,但问题是我想在C程序中链接库。

My Makefile for now is like:

我的Makefile现在是:

all: test
test: main.o com.o
  gcc main.o com.o -o test

main.o: main.c
    gcc -c main.c -o main.o

com.o: com.c
    gcc -c com.c -Wl,-rpath=/usr/local/lib -Wl,LIBDIR -o com.o

clean:
    rm -rf *o test

In my file com.c I include the file modbus.h like this:

在我的文件com。我包括了文件modbus。h是这样的:

#include <modbus.h>

And I always get the error:

我总是会犯错误:

fatal error: modbus.h: No such file or directory.

If it can help when I did make install, the code return me this:

如果它能在我做安装的时候有所帮助,代码会返回给我:

If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the '-LLIBDIR' flag during linking and do at least one of the following:

如果您碰巧想要链接到给定目录中的已安装的库,那么您必须使用libtool,并指定库的完整路径名,或者在链接过程中使用“-LLIBDIR”标志,并至少执行以下操作之一:

  • add LIBDIR to the `LD_LIBRARY_PATH' environment variable during execution
  • 在执行期间将LIBDIR添加到“LD_LIBRARY_PATH”环境变量中。
  • add LIBDIR to the `LD_RUN_PATH' environment variable during linking
  • 在链接期间将LIBDIR添加到“LD_RUN_PATH”环境变量中。
  • use the `-Wl,-rpath -Wl,LIBDIR' linker flag
  • 使用“-Wl,-rpath -Wl,LIBDIR”链接标志。
  • have your system administrator add LIBDIR to `/etc/ld.so.conf'
  • 让系统管理员将LIBDIR添加到' /etc/ lsd .conf'

1 个解决方案

#1


2  

It seems like the modbus.h is not in the standard include directory. You should to add the -I/<includes_path> flag to gcc options.

好像是modbus。h不在标准中包含目录。您应该将i / 标志添加到gcc选项中。

I suppose here:

我想在这里:

gcc -I/<include_dir_path> -c com.c -Wl,-rpath=/usr/local/lib -Wl,LIBDIR -o com.o

#1


2  

It seems like the modbus.h is not in the standard include directory. You should to add the -I/<includes_path> flag to gcc options.

好像是modbus。h不在标准中包含目录。您应该将i / 标志添加到gcc选项中。

I suppose here:

我想在这里:

gcc -I/<include_dir_path> -c com.c -Wl,-rpath=/usr/local/lib -Wl,LIBDIR -o com.o