2014-05-12 3 views
1

Linux에서 libmodbus 라이브러리로 작업 할 때 많은 어려움이있을 것으로 예상됩니다.치명적인 오류 : modbus.h : 해당 파일이나 디렉토리가 없습니다.

sudo make install 명령을 사용하여 libmodbus를 설치했으나 make 후에는 C 라이브러리에서 라이브러리를 링크하려고 할 때 문제가 발생합니다. 지금은

내 메이크 같다 :

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 

내 파일 com.c에서이 같은 파일 modbus.h 포함

#include <modbus.h> 

을 그리고 난 항상 오류가 발생합니다 :

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

설치를 완료했을 때 도움이된다면 코드에서 다음과 같이 반환합니다.

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:

  • add LIBDIR to the `LD_LIBRARY_PATH' environment variable during execution
  • add LIBDIR to the `LD_RUN_PATH' environment variable during linking
  • use the `-Wl,-rpath -Wl,LIBDIR' linker flag
  • have your system administrator add LIBDIR to `/etc/ld.so.conf'
+0

참조가 (http://stackoverflow.com/questions/22697543/compiling-a-program-that-includes- [libmodbus'에서 C '가 포함 된 progam 컴파일]를 libmodbus-in-c)'main.o'와'com.o' 파일을 만드는 데 걸리는 어려움을 극복해야합니다. –

답변

2

modbus.h은 표준 포함 디렉토리에없는 것 같습니다. gcc 옵션에 -I/<includes_path> 플래그를 추가해야합니다.

여기 가정 :

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

문제는 매뉴얼에 -I 와 같은 소스 코드가 포함되어 있어도 main.o 파일이 인식되지 않는 것과 같은 또 다른 오류가 발생한다는 것입니다. collect2 : ld가 1 종료 상태를 반환했습니다 – JoSav

+0

@JoSav : "* Another 오류 * "-> 또 다른 질문입니다. – alk

+0

다른 오류가있는 것은 아닙니다. 이미이 솔루션을 시도했기 때문에 Google에서 "make_path_dir"이 유용하지 않아 소스 코드가 아닌 librairy와 makefile을 연결해야한다고 말했기 때문입니다. – JoSav

관련 문제