c++ Netbeans 7.2.1 linking boost libraries correctly

巧了我就是萌 提交于 2019-12-13 06:29:20

问题


I've recently switched from visual studio 2010 express to using NetBeans, and i'm already very impressed with the layout and simplicity, even though it did take a bit of nudging to compile right. However, i've got another problem. When i tested to see if boost would work as well, i included the file boost/signals.hpp in a main.cpp and then went to the additional library directories in the project options and added the lib directory of my boost install, same as i would do in visual studio. After all this, i get a bunch of undefined references anyway.

I'm using the mingw compiler with msys and i have boost version 1.47 if that makes any difference. I can confirm that this same install of boost works fine when using visual studio.

Here is the build log.

"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory m`/c/Users/me/Documents/NetBeansProjects/Syncopate5/Syncopate5'
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/syncopate5.exe
make[2]: Entering directory `/c/Users/me/Documents/NetBeansProjects/Syncopate5/Syncopate5'
mkdir -p dist/Debug/MinGW-Windows
g++.exe     -o dist/Debug/MinGW-Windows/syncopate5 build/Debug/MinGW-Windows/main.o -L/C/Program\ Files\ \(x86\)/boost/boost_1_47/lib 
build/Debug/MinGW-Windows/main.o: In function `ZN5boost7signal0IvNS_10last_valueIvEEiSt4lessIiENS_8functionIFvvEEEED2Ev':
C:\Users\me\Documents\NetBeansProjects\Syncopate5\Syncopate5/../../../../../../Program Files (x86)/boost/boost_1_47/boost/signals/signal_template.hpp:139: undefined reference to `boost::signals::trackable::~trackable()'
C:\Users\me\Documents\NetBeansProjects\Syncopate5\Syncopate5/../../../../../../Program Files (x86)/boost/boost_1_47/boost/signals/signal_template.hpp:139: undefined reference to `boost::signals::detail::signal_base::~signal_base()'
make[2]: Leaving directory `/c/Users/me/Documents/NetBeansProjects/Syncopate5/Syncopate5'
C:\Users\me\Documents\NetBeansProjects\Syncopate5\Syncopate5/../../../../../../Program Files (x86)/boost/boost_1_47/boost/signals/signal_template.hpp:139: undefined reference to `boost::signals::detail::signal_base::~signal_base()'
make[1]: Leaving directory `/c/Users/me/Documents/NetBeansProjects/Syncopate5/Syncopate5'
build/Debug/MinGW-Windows/main.o: In function `ZN5boost7signal0IvNS_10last_valueIvEEiSt4lessIiENS_8functionIFvvEEEEC2ERKS2_RKS4_':
C:\Users\me\Documents\NetBeansProjects\Syncopate5\Syncopate5/../../../../../../Program Files (x86)/boost/boost_1_47/boost/signals/signal_template.hpp:197: undefined reference to `boost::signals::detail::signal_base::signal_base(boost::function2<bool, boost::signals::detail::stored_group, boost::signals::detail::stored_group> const&, boost::any const&)'
C:\Users\me\Documents\NetBeansProjects\Syncopate5\Syncopate5/../../../../../../Program Files (x86)/boost/boost_1_47/boost/signals/signal_template.hpp:197: undefined reference to `boost::signals::detail::signal_base::~signal_base()'
collect2.exe: error: ld returned 1 exit status
make[2]: *** [dist/Debug/MinGW-Windows/syncopate5.exe] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

Edit:

After trying to add the required lib file manually via the add libraries dialog in the project properties, i receive this error.

"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/c/Users/me/Documents/NetBeansProjects/Syncopate5/Syncopate5'
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/syncopate5.exe
make[2]: Entering directory `/c/Users/me/Documents/NetBeansProjects/Syncopate5/Syncopate5'
make[2]: *** No rule to make target `../../../../../../Program Files \(x86\)/boost/boost_1_47/lib/libboost_signals-vc100-mt-1_47.lib', needed by `dist/Debug/MinGW-Windows/syncopate5.exe'.  Stop.
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
make[2]: Leaving directory `/c/Users/me/Documents/NetBeansProjects/Syncopate5/Syncopate5'
make[1]: Leaving directory `/c/Users/me/Documents/NetBeansProjects/Syncopate5/Syncopate5'

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

回答1:


This depends on how you built the project.

If you built the project from an existing makefile, your library paths and libraries should be present in the build environment.

If you built the project by hand by piece-mealing the source, include, and libraries in individually, you will need to explicitly add the libraries that you want.

Specifically, looking at your updated build log, it appears you're not linking the required library and instead added it as a target somehow.

Right click on your project, go to Properties, under the Build tab look toward Linker, Here is where you should specify your link path and your dynamic/static libraries.




回答2:


After hours of googling and reading, i have discovered a little more about boost and finally found and understand my problem. When i originally obtained my install of boost, it was from BoostPro which has all the header only objects, as well as precompiled binaries for vc++ ONLY. After obtaining the most recent version of boost, and boost.build to create gcc versions of the libraries and linking against them, it worked without a hitch. Thanks Tyler Jandreau an Joachim Pileborg for answering my inherently flawed question :.



来源:https://stackoverflow.com/questions/14767550/c-netbeans-7-2-1-linking-boost-libraries-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!