내 C++ 프로젝트에 ANSI-C 용 gnuplot 인터페이스 인 gnuplot_i를 사용하려고합니다. (다운로드 섹션에서 here을 참조하십시오.) 그것은 하나의 헤더와 하나의 소스 파일로만 구성됩니다. Makefile은 객체 파일을 생성하기 때문에 프로젝트에이 두 파일을 완전히 통합하기로 결정했습니다. 그러나 앞서 언급 한 소스 파일에서 구현 된 함수에 대한 정의되지 않은 참조 오류가 발생합니다. 다음의 간단한 예 (MAIN.CPP) 고려 : 헤더 파일 here 얻을 수`gnuplot_init() '에 대한 정의되지 않은 참조
#include <gnuplot_i.h>
int main(int argc, char** argv) {
gnuplot_ctrl * h;
h = gnuplot_init();
return 0;
}
소스 파일을 here.
내가 오류는 다음 그러나 gnuplot_init()
가 다음 프로그램을 연결하는 데 사용되는 오브젝트 파일로 컴파일됩니다 소스 파일에 구현되어
build/Debug/GNU-Linux/main.o: In function `main':
/<some path>/proj/test/main.cpp:18: undefined reference to `gnuplot_init()'
collect2: error: ld returned 1 exit status
. 아래의 전체 로그에서이를 볼 수 있습니다.
$ nm gnuplot_i.o | grep gnuplot_init
0000000000000000 T gnuplot_init
전체 로그 :
cd '/<some path>/proj/test'
/usr/bin/make -f Makefile CONF=Debug clean
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .clean-conf
make[1]: Entering directory '/<some path>/proj/test'
rm -f -r build/Debug
rm -f dist/Debug/GNU-Linux/test
make[1]: Leaving directory '/<some path>/proj/test'
CLEAN SUCCESSFUL (total time: 52ms)
cd '/<some path>/proj/test'
/usr/bin/make -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/<some path>/proj/test'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/test
make[2]: Entering directory '/<some path>/proj/test'
mkdir -p build/Debug/GNU-Linux
rm -f "build/Debug/GNU-Linux/gnuplot_i.o.d"
gcc -c -g -I. -MMD -MP -MF "build/Debug/GNU-Linux/gnuplot_i.o.d" -o build/Debug/GNU-Linux/gnuplot_i.o gnuplot_i.c
gnuplot_i.c: In function ‘gnuplot_tmpfile’:
gnuplot_i.c:696:5: warning: implicit declaration of function ‘close’ [-Wimplicit-function-declaration]
close(unx_fd);
^~~~~
mkdir -p build/Debug/GNU-Linux
rm -f "build/Debug/GNU-Linux/main.o.d"
g++ -c -g -I. -MMD -MP -MF "build/Debug/GNU-Linux/main.o.d" -o build/Debug/GNU-Linux/main.o main.cpp
mkdir -p dist/Debug/GNU-Linux
g++ -o dist/Debug/GNU-Linux/test build/Debug/GNU-Linux/gnuplot_i.o build/Debug/GNU-Linux/main.o
build/Debug/GNU-Linux/main.o: In function `main':
/<some path>/proj/test/main.cpp:18: undefined reference to `gnuplot_init()'
collect2: error: ld returned 1 exit status
make[2]: *** [nbproject/Makefile-Debug.mk:64: dist/Debug/GNU-Linux/test] Error 1
make[2]: Leaving directory '/<some path>/proj/test'
make[1]: *** [nbproject/Makefile-Debug.mk:60: .build-conf] Error 2
make[1]: Leaving directory '/<some path>/proj/test'
make: *** [nbproject/Makefile-impl.mk:40: .build-impl] Error 2
BUILD FAILED (exit value 2, total time: 304ms)
내가 넷빈즈 Makefile들로부터 자동 생성 buildsystem을 사용하고 있습니다으로 매우 크고 복잡 또한 생성 된 오브젝트 파일은 필요한 기호가 포함되어 있습니다. 그러나 명령이 발행 된 로그에서 꽤 분명해야합니다. 여기서 정확히 무엇이 틀렸는가? C 개체 파일과 C++ 개체 파일을 링크하는 것이 문제입니까? 내 이해에서 그렇게해서는 안됩니다.