I'm trying to use the Libnoise library and I keep get this error:
F:\PortableApps\Documents\Adventure³>g++ Compiled/*.o -o Adventure3 -L./Libs -static -lglew32 -lglfw3dll -lopengl32 -lfreetype -lnoise -static-libgcc-static-libstdc++ Resources/icon.res
f:/portableapps/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lnoise
collect2.exe: error: ld returned 1 exit status
I have the libnoise.lib in my Libs folder. I tried with -llibnoise instead, and I get:
F:\PortableApps\Documents\Adventure³>g++ Compiled/*.o -o Adventure3 -L./Libs -static -lglew32 -lglfw3dll -lopengl32 -lfreetype -llibnoise -static-libgcc -static-libstdc++ Resources/icon.res
Compiled/Generator.o:Generator.cpp:(.text+0x3d): undefined reference to `noise::module::Perlin::GetValue(double, double, double) const'
Compiled/Generator.o:Generator.cpp:(.text+0x8a): undefined reference to `noise::module::Perlin::Perlin()'
Compiled/Generator.o:Generator.cpp:(.text$_ZN5noise6module6PerlinD1Ev[__ZN5noise6module6PerlinD1Ev]+0xa): undefined reference to `vtable for noise::module::Perlin'
Compiled/Generator.o:Generator.cpp:(.text$_ZN5noise6module6PerlinD1Ev[__ZN5noise6module6PerlinD1Ev]+0x19): undefined reference to `noise::module::Module::~Module()'
collect2.exe: error: ld returned 1 exit status
I don't know how to manually compile the source, it always return me a WinMain#16 error, no matter what I try to make.
Now, I really don't know what to do...
Anyone have a solution?
-l option of gcc supposes that library got name starting with lib, so -lnoise would link libnoise.
Usually .lib is a n import library or static library. The problems related to import libraries described here: How do import libraries work and why doesn't MinGW need them?
In relation to libnoise: Netbeans C++ using MinGW and the libnoise library
Related
I use g++ to link my project (an executable mono_kitti) and my project is dependent on a thirdparty library Pangolin. When I do the link action with -lpangolin option:
g++ -L../../lib -lORB_SLAM2 -lpangolin mono_kitti.o -o mono_kitti
it returns:
mono_kitti.o:(.data+0x0): undefined reference to `vtable for pangolin::Handler'
mono_kitti.o:(.data+0x8): undefined reference to `vtable for pangolin::HandlerScroll'
mono_kitti.o: In function `pangolin::Handler::~Handler()':
mono_kitti.cc:(.text._ZN8pangolin7HandlerD2Ev[_ZN8pangolin7HandlerD5Ev]+0x13): undefined reference to `vtable for pangolin::Handler'
mono_kitti.o: In function `pangolin::HandlerScroll::~HandlerScroll()':
mono_kitti.cc:(.text._ZN8pangolin13HandlerScrollD2Ev[_ZN8pangolin13HandlerScrollD5Ev]+0x13): undefined reference to `vtable for pangolin::HandlerScroll'
collect2: error: ld returned 1 exit status
But When I use this command:
g++ -L../../lib -lORB_SLAM2 mono_kitti.o /usr/local/lib/libpangolin.so -o mono_kitti
it succeeded.
But it failed again when I tried to swap the order of them:
g++ -L../../lib -lORB_SLAM2 /usr/local/lib/libpangolin.so mono_kitti.o -o mono_kitti
and returns things identical with the first case above (-lpangolin option).
I'm very confused about these results, could someone can explain the differece between them? Many thanks!
When the linker sees the library (the -lpangolin option in your case), it doesn't yet have any unresolved references to that library, so it discards it.
If you put the object file before the library, so your command line look like e.g.
g++ mono_kitti.o -L../../lib -lORB_SLAM2 -lpangolin -o mono_kitti
Then the linker have all the unresolved references from mono_kitti.o and will pull them from the libraries.
I'm trying to add caffe to an existing project. I get 99 undefined reference errors, suggesting that it has something to do with linking libraries. The errors mention caffe, boost and google (relates to gflags or glog).
Linker command: (libcaffe is in /home/torcs/lib)
g++ main.o linuxspec.o -L/home/torcs/export/lib -lopenal -lalut -lvorbisfile -L/usr/lib -L/home/torcs/lib -lracescreens -lrobottools -lclient -lconfscreens -ltgf -ltgfclient -ltxml -lplibul -lraceengine -lmusicplayer -llearning -lplibjs -lplibssgaux -lplibssg -lplibsm -lplibsl -lplibsg -lplibul -lglut -lGLU -lGL -lpng -lz -ldl -lXrandr -lXrender -lXxf86vm -lXmu -lXi -lXt -lSM -lICE -lXext -lX11 -lm -lcaffe -lglog -o torcs-bin
Linker error (first 2 and final 2):
/home/torcs/export/lib/librobottools.so: undefined reference to `caffe::FillerParameter::_default_type_'
/home/torcs/export/lib/librobottools.so: undefined reference to `void caffe::caffe_gpu_set<float>(int, float, float*)'
...
/home/torcs/export/lib/librobottools.so: undefined reference to `caffe::NetStateRule::NetStateRule()'
/home/torcs/export/lib/librobottools.so: undefined reference to `caffe::Timer::MilliSeconds()'
collect2: error: ld returned 1 exit status
I added -lcaffe and tried libcaffe.a and libcaffe.so separately but the number of errors is not decreasing as I add libraries. If I misspel -lcaff it says cannot find libcaffe, which it doesn't do otherwise, so the lib is included correctly I guess.
I read up on linker order (windows background) and found that the symbols only get added if they are on the required symbols list. More specific libs should be last, dependent libs should be first. I figured that if I only add lcaffe at the end, the unrecognized symbol list should be populated, and at least the caffe symbols would be recognized, and maybe replaced by other dependencies. But that doesn't happen.
I tried to find whether libcaffe supplies the references. For the final undefined reference (caffe::Timer::MilliSeconds()), nm libcaffe.a finds:
0000000000188090 T _ZN5caffe5Timer12MilliSecondsEv
0000000000187910 T _ZN5caffe8CPUTimer12MilliSecondsEv
Which suggest the reference is in the lib. But the undefined reference error doesn't go away.
I also tried adding boost libs and glog, didn't help.
Edit. There is some additional weird behaviour going on. I think it is unrelated, but am not sure. The first time I build after a make clean I get an error about include <random>:
/usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
This prevents the o files and librobottools.so from getting built. But if I make again, the c++11 error disappears, this lib does get build, and I see the 99 undefined reference errors.
I am getting static link errors to boost's non header only library. Let's solve it together:
The final binary is supposed to be built using libraries(libbasemainif.a for example) separately built as the higher layers. One of those layers, uses boost::filesystem.
Have a look at the simplified vesrion of g++ command:
g++ /mylis/1.a /mylibs/2.a
-L/myboost/Linux-x86_64/lib64
-Wl,-rpath,/myboost/Linux-x86_64/lib64 -Wl,-Bstatic
-lboost_thread-mt -lboost_system-mt -lboost_filesystem-mt -lboost_date_time-mt
-Wl,-Bdynamic
-Wl,-rpath,/myinstall/usr/local/lib64 -L/myinstall/usr/local/lib64 -Wl,
-Bstatic -lmyblahblah-static -Wl,-Bdynamic **-lbasemainif** -lbaseif -ldl -rdynamic -lz -lrt
-L/mypackage1/Linux-x86_64/debug/lib -L /mypackage2/18.1/Linux-x86_64/debug/lib -lpthread -Wl,-rpath,$ORIGIN/../lib64
and this is the error :
/blahblah/lib/libbasemainif.a(errorreportfile.o):
In function `boost::filesystem3::remove(boost::filesystem3::path const&, boost::system::error_code&)':
/myboost/Linux-x86_64/include/boost/filesystem/v3/operations.hpp:411:
undefined reference to boost::filesystem3::detail::remove(boost::filesystem3::path const&, boost::system::error_code*)'
collect2: ld returned 1 exit status
If I remove -Wl,-Bstatic the g++ command executes successfully.But this is not an option in production.
The libboost_filesystem.a is available. And all of the laibraries in every layer used boost from the same location.
Can you please tell me why I am getting this error? Thank you
You should pass to gcc library that implements function after the piece which references it. Something like: -lbasemainif -lboost_filesystem-mt. This is how gcc linker resolves dependencies.
Here is great detailed explanation.
When I build a simple C++ program with glog library (Google's logging library which is not used in the code), I get "undefined reference" errors. When I remove the -lglog from the build command, the link succeeds.
Notice that the library that I added to the link is not used in the code at all and despite that it caused the build to fail. In addition, the glog and log4cpp libraries are supposed to be independent.
Can you explain this unusual behavior?
Environment: Ubuntu 14.04
Code:
//test.cpp
#include "log4cpp/Appender.hh"
#include "log4cpp/FileAppender.hh"
int main() {
log4cpp::Appender *appender;
appender = new log4cpp::FileAppender("default", "program.log");
return 0;
}
Working build command:
$ g++ test.cpp -llog4cpp -lpthread
Failing build command:
$ g++ test.cpp -llog4cpp -lglog -lpthread
//usr/local/lib/liblog4cpp.so: undefined reference to `pthread_key_create'
//usr/local/lib/liblog4cpp.so: undefined reference to `pthread_getspecific'
//usr/local/lib/liblog4cpp.so: undefined reference to `pthread_key_delete'
//usr/local/lib/liblog4cpp.so: undefined reference to `pthread_setspecific'
collect2: error: ld returned 1 exit status
EDIT:
This command also builds successfully:
g++ test.cpp -llog4cpp -lpthread -lglog
This command fails (change the order of libs):
$ g++ test.cpp -llog4cpp -lglog -lpthread
//usr/local/lib/liblog4cpp.so: undefined reference to `pthread_key_create'
//usr/local/lib/liblog4cpp.so: undefined reference to `pthread_getspecific'
//usr/local/lib/liblog4cpp.so: undefined reference to `pthread_key_delete'
//usr/local/lib/liblog4cpp.so: undefined reference to `pthread_setspecific'
collect2: error: ld returned 1 exit status
This succeeds:
$ g++ test.cpp -pthread -llog4cpp
This fails:
$ g++ test.cpp -pthread -llog4cpp -lglog
EDIT 2:
I studied the duplicate suggestions (1) and (2) to find out maybe there's something useful to me there, but it turned out irrelevant because these cases doesn't address the situation where a library that is not used in the code is added to the link and make it fail.
EDIT 3:
The files from my environment (glog libs, log4cpp libs, used log4cpp headers and test.cpp): log_test.zip.
I have compiled libcurl using mingw32 and am trying to link it with my program using mingw32 for a Windows system from my Linux machine.
I was outputted the files, libcurl-4.dll libcurl.a libcurl.la libcurl.lai.
I have included them in my mingw32 libs folder at: /usr/x86_64-w64-mingw32/lib
I was able to find a few other topics on linking with the libstdc++ and libgcc to take care dependency errors while executed but when trying to add libcurl.a it will not compile period.
I used the following:
$ x86_64-w64-mingw32-g++ main.cpp -o hello.exe -static-libgcc -static-libstdc++ -static "/usr/x86_64-w64-mingw32/lib/libcurl.a" -lpthread
However, I cannot not get it to use the libcurl.a and am continuing to receive these errors.
/tmp/ccIceRus.o:main.cpp:(.text+0xde): undefined reference to `__imp_curl_easy_init'
/tmp/ccIceRus.o:main.cpp:(.text+0x106): undefined reference to `__imp_curl_easy_setopt'
/tmp/ccIceRus.o:main.cpp:(.text+0x122): undefined reference to `__imp_curl_easy_setopt'
/tmp/ccIceRus.o:main.cpp:(.text+0x13e): undefined reference to `__imp_curl_easy_setopt'
/tmp/ccIceRus.o:main.cpp:(.text+0x159): undefined reference to `__imp_curl_easy_setopt'
/tmp/ccIceRus.o:main.cpp:(.text+0x169): undefined reference to `__imp_curl_easy_perform'
/tmp/ccIceRus.o:main.cpp:(.text+0x180): undefined reference to `__imp_curl_easy_strerror'
/tmp/ccIceRus.o:main.cpp:(.text+0x197): undefined reference to `__imp_curl_easy_cleanup'
/usr/bin/x86_64-w64-mingw32-ld: /tmp/ccIceRus.o: bad reloc address 0x80 in section `.xdata'
collect2: error: ld returned 1 exit status
What am I doing wrong?. I can not get past this. I know it has to be some stupid issue.
Thank you.
I was able to solve the question by specifying -DCURL_STATICLIB, as well as linking some other dependencies.
x86_64-w64-mingw32-g++ main.cpp -o hello.exe -DCURL_STATICLIB -static -lstdc++ -lgcc -lpthread -lcurl -lwldap32 -lws2_32