编译后链接卷曲在netbeans构建中失败

时间:2011-07-03 16:08:03

标签: c++ netbeans curl build cygwin

如果我试试这个

g++ -o testApp main.cpp -I/usr/local/include -L/usr/local/lib -lcurl -lssl -lcrypto -lz -lz

它完美无缺......

但是如果我想直接使用netbeans运行我的示例应用程序,它会给我一些错误。

这里是Makefile-Debug.mk

的一部分
# Build Targets
.build-conf: ${BUILD_SUBPROJECTS}
    "${MAKE}"  -f nbproject/Makefile-${CND_CONF}.mk ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/SampleApp.exe

${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/SampleApp.exe: ${OBJECTFILES}
    ${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}
    ${LINK.cc} -I/usr/local/lib -lcurl -lssl -lcrypto -lz -lz -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/SampleApp ${OBJECTFILES} ${LDLIBSOPTIONS}

${OBJECTDIR}/main.o: main.cpp
    ${MKDIR} -p ${OBJECTDIR}
    ${RM} $@.d
    $(COMPILE.cc) -g -MMD -MP -MF $@.d -o ${OBJECTDIR}/main.o main.cpp

netbeans构建输出的结果:

"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .clean-conf
make[1]: Entering directory `/cygdrive/c/Users/<MY_USERNAME>/Documents/NetBeansProjects/SampleApp'
rm -f -r build/Debug
rm -f dist/Debug/Cygwin-Windows/SampleApp.exe
make[1]: Leaving directory `/cygdrive/c/Users/<MY_USERNAME>/Documents/NetBeansProjects/SampleApp'

CLEAN SUCCESSFUL (total time: 1s)
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/cygdrive/c/Users/<MY_USERNAME>/Documents/NetBeansProjects/SampleApp'
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin-Windows/SampleApp.exe
make[2]: Entering directory `/cygdrive/c/Users/<MY_USERNAME>/Documents/NetBeansProjects/SampleApp'
mkdir -p build/Debug/Cygwin-Windows
rm -f build/Debug/Cygwin-Windows/main.o.d
g++.exe    -c -g -MMD -MP -MF build/Debug/Cygwin-Windows/main.o.d -o build/Debug/Cygwin-Windows/main.o main.cpp
mkdir -p dist/Debug/Cygwin-Windows
g++.exe     -I/usr/local/lib -lcurl -lssl -lcrypto -lz -lz -o dist/Debug/Cygwin-Windows/SampleApp build/Debug/Cygwin-Windows/main.o -L/usr/local/lib
build/Debug/Cygwin-Windows/main.o: In function `main':
/cygdrive/c/Users/<MY_USERNAME>/Documents/NetBeansProjects/SampleApp/main.cpp:23: undefined reference to `_curl_easy_init'
/cygdrive/c/Users/<MY_USERNAME>/Documents/NetBeansProjects/SampleApp/main.cpp:25: undefined reference to `_curl_easy_setopt'
/cygdrive/c/Users/<MY_USERNAME>/Documents/NetBeansProjects/SampleApp/main.cpp:28: undefined reference to `_curl_easy_setopt'
/cygdrive/c/Users/<MY_USERNAME>/Documents/NetBeansProjects/SampleApp/main.cpp:29: undefined reference to `_curl_easy_setopt'
make[2]: Leaving directory `/cygdrive/c/Users/<MY_USERNAME>/Documents/NetBeansProjects/SampleApp'
/cygdrive/c/Users/<MY_USERNAME>/Documents/NetBeansProjects/SampleApp/main.cpp:31: undefined reference to `_curl_easy_perform'
make[1]: Leaving directory `/cygdrive/c/Users/<MY_USERNAME>/Documents/NetBeansProjects/SampleApp'
/cygdrive/c/Users/<MY_USERNAME>/Documents/NetBeansProjects/SampleApp/main.cpp:32: undefined reference to `_curl_easy_cleanup'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/Cygwin-Windows/SampleApp.exe] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 2s)

这里可能出现什么问题......?

1 个答案:

答案 0 :(得分:0)

-L选项需要在命令行中使用-l指定的库之前。

因此,如果您需要-L / usr / local / lib for libcurl(如在您的小样本中),您需要首先将-L指定为正确的目录,然后使用正确的lib指定-l名。