Gurus!
I am using Ubuntu 13.10 64-bit to compile latest Google RE2 library, but 'make testinstall' failed to compile, here is the log:
kevin#ubuntu:~/re2$ make testinstall
cp testinstall.cc obj
(cd obj && g++ -I/usr/local/include -L/usr/local/lib testinstall.cc -lre2 -pthread -o testinstall)
/tmp/ccSsaSXS.o: In function main':
testinstall.cc:(.text+0xce): undefined reference tore2::FilteredRE2::FirstMatch(re2::StringPiece const&, std::vector > const&) const'
/usr/local/lib/libre2.so: undefined reference to pthread_rwlock_rdlock'
/usr/local/lib/libre2.so: undefined reference topthread_rwlock_wrlock'
/usr/local/lib/libre2.so: undefined reference to pthread_rwlock_destroy'
/usr/local/lib/libre2.so: undefined reference topthread_rwlock_init'
/usr/local/lib/libre2.so: undefined reference to `pthread_rwlock_unlock'
collect2: error: ld returned 1 exit status
make: * [testinstall] Error 1
I tried to replace -pthread with -lpthread, still failed, then I dumped libre2.so and found that pthread_xxx is in it.
Here is the issue tracking in RE2 forum: https://code.google.com/p/re2/issues/detail?id=100
Anyone here have ever complied RE2 successfully ? Thank you!
See this comment:
Adding -pthread to LDFLAGS seems to fix make test (all tests are
passing), but not make testinstall.
That will get you to the next error
Depending on what you build it for 'make testinstall' might not be necessary.
I just needed to get python re2 port working, and this can be installed after running make install.
I encounter this problem before. Modify the makefile and use -lpthread instead of -pthread.
So I tried looking for the lines in testinstall.cc that were causing the symbol errors and I found out that the only line was on line 18:
18 - f.firstMatch(:abbccc:, ids);
I commented this line out (so that the FullMatch function below is still called) and just ran g++ testinstall.cc -lre2 -pthread -o testinstall (basically what the Makefile does) and I was able to get a binary successfully. Although this might not really solve the problem, its good to know that we can still use the RE2::Fullmatch and partial match functions
If I were to guess, maybe there is a dependency somewhere inside the filtered_re2 module?
I had the same problem. But if you compile with -static everything goes well.
nm -C shows that the "missing" symbol exists in both .a and .so files.
Related
I'm getting some strange compiler/linker errors when trying to use boost::shared_mutex. I'm using boost v1.61 on a VM running 32-bit rhel 6.2.
Code that causes error:
hpp file:
#include <boost/thread/shared_mutex.hpp>
class SharedData
{
public:
SharedData();
~SharedData();
void packMessage(std::shared_ptr<Message> s);
private:
// mutex that allows multiple read, single write protection
boost::shared_mutex m_sharedMutex;
};
cpp file:
void SharedData::packMessage(std::shared_ptr<Message> s)
{
// get shared read access
boost::shared_lock<boost::shared_mutex> lock(m_sharedMutex); // <- this line causes the errors
// read stuff here
}
make output:
CMakeFiles/tester.dir/__/src/SharedData/SharedData.cpp.o: In function `boost::detail::interruption_checker::interruption_checker(pthread_mutex_t*, pthread_cond_t*)':
/usr/local/include/boost/thread/pthread/thread_data.hpp:195: undefined reference to `boost::detail::get_current_thread_data()'
CMakeFiles/tester.dir/__/src/SharedData/SharedData.cpp.o: In function `boost::condition_variable::wait(boost::unique_lock<boost::mutex>&)':
/usr/local/include/boost/thread/pthread/condition_variable.hpp:81: undefined reference to `boost::this_thread::interruption_point()'
CMakeFiles/tester.dir/__/src/SharedData/SharedData.cpp.o: In function `boost::shared_mutex::lock_shared()':
/usr/local/include/boost/thread/pthread/shared_mutex.hpp:186: undefined reference to `boost::this_thread::disable_interruption::disable_interruption()'
/usr/local/include/boost/thread/pthread/shared_mutex.hpp:193: undefined reference to `boost::this_thread::disable_interruption::~disable_interruption()'
/usr/local/include/boost/thread/pthread/shared_mutex.hpp:193: undefined reference to `boost::this_thread::disable_interruption::~disable_interruption()'
collect2: error: ld returned 1 exit status
make[2]: *** [bin/tester] Error 1
Everywhere I've searched has said that these errors mean I need to link the boost_thread library, which I've done in my cmake file (boost_system is included for other code in this same project):
target_link_libraries(${BINARY_NAME} boost_thread boost_system)
But the errors persist.
Originally I was using the boost 1.41 libraries that were already installed on my machine. When I hit these errors I ran yum remove boost-devel and then manually installed boost 1.61 to see if that would correct the errors. Is there something extra I needed to add to the ./bootstrap.sh or ./b2 install commands? I can see libboost_thread.a in /usr/local/lib, so I assumed that meant the thread library was built correctly.
Any thoughts on what is causing these errors? Thanks!
Edit:
Cmake's log didn't have anything useful I could see, but make VERBOSE=1 gives the following output:
cd /home/craig/dev/myProject/build/test && /usr/bin/cmake -E cmake_link_script CMakeFiles/tester.dir/link.txt --verbose=1
/opt/rh/devtoolset-2/root/usr/bin/c++ -std=c++11 -ggdb -Wall -Werror -fprofile-arcs -ftest-coverage -fPIC -O0 -pedantic -Wl,--export-dynamic CMakeFiles/tester.dir/utilities/googletest/googletest/src/gtest-all.cc.o CMakeFiles/tester.dir/tester.cpp.o CMakeFiles/tester.dir/SharedData/testSharedData.cpp.o CMakeFiles/tester.dir/Common/testFifo.cpp.o CMakeFiles/tester.dir/Common/testCsu.cpp.o CMakeFiles/tester.dir/Messages/testMessage.cpp.o CMakeFiles/tester.dir/__/src/SharedData/SharedData.cpp.o CMakeFiles/tester.dir/__/src/Common/Fifo.cpp.o CMakeFiles/tester.dir/__/src/Common/Csu.cpp.o -o ../bin/tester -rdynamic -lboost_system -lpthread
CMakeFiles/tester.dir/__/src/SharedData/SharedData.cpp.o: In function `boost::detail::interruption_checker::interruption_checker(pthread_mutex_t*, pthread_cond_t*)':
/usr/local/include/boost/thread/pthread/thread_data.hpp:195: undefined reference to `boost::detail::get_current_thread_data()'
CMakeFiles/tester.dir/__/src/SharedData/SharedData.cpp.o: In function `boost::condition_variable::wait(boost::unique_lock<boost::mutex>&)':
/usr/local/include/boost/thread/pthread/condition_variable.hpp:81: undefined reference to `boost::this_thread::interruption_point()'
CMakeFiles/tester.dir/__/src/SharedData/SharedData.cpp.o: In function `boost::shared_mutex::lock_shared()':
/usr/local/include/boost/thread/pthread/shared_mutex.hpp:186: undefined reference to `boost::this_thread::disable_interruption::disable_interruption()'
/usr/local/include/boost/thread/pthread/shared_mutex.hpp:193: undefined reference to `boost::this_thread::disable_interruption::~disable_interruption()'
/usr/local/include/boost/thread/pthread/shared_mutex.hpp:193: undefined reference to `boost::this_thread::disable_interruption::~disable_interruption()'
Turns out my question is just like everyone else's.
#jww suggested I show the actual compile and link command invocation, not CMake's output, which I've added to my question. As you can see, the command is linking boost_system and pthread, but not boost_thread.
Digging into my project I realized that I had added boost_thread to my release build, but not into my unit test build, which is what I was trying to compile. Adding boost_thread to the unit test's CMakeLists.txt removed the error immediately.
I used the MinGW installation at http://nuwen.net/mingw.html
I ran the second.cpp test found at:
http://tabreziqbal.wordpress.com/2006/03/16/how-to-test-c-boost-installation/
(I used the correct commands to run from the comments, which was
g++ -o second second.cpp -lboost_filesystem)
I get the following error:
C:\Users\user\Projects\Programming\C++\boostTest2>g++ -o second second.cpp -lboost_filesystem
C:\Users\user\AppData\Local\Temp\ccDlbKGy.o:second.cpp:(.text+0x102): undefined reference to boost::system::generic_cat
egory()'
C:\Users\user\AppData\Local\Temp\ccDlbKGy.o:second.cpp:(.text+0x10c): undefined reference toboost::system::generic_cat
egory()'
C:\Users\user\AppData\Local\Temp\ccDlbKGy.o:second.cpp:(.text+0x116): undefined reference to boost::system::system_cate
gory()'
C:\MinGW\bin/ld.exe: C:\Users\user\AppData\Local\Temp\ccDlbKGy.o: bad reloc address 0xe in section.text$_ZN5boost6syst
em14error_categoryD1Ev[__ZN5boost6system14error_categoryD1Ev]'
C:\MinGW\bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
I know there's an installation test feature of boost that I found on
http://gcc.gnu.org/testing/testing-boost.html
but those files aren't included with the distribution from nuwen.net (so I'd have to do it myself).
And help is appreciated - I figure I'm just screwing up something minor (I hope anyway).
Thanks all!
It's not correct command, you should link boost::system too (errors are undefined references to boost::system::system_category).
Correct command will be g++ -o second second.cpp -lboost_system -lboost_filesystem
I am trying to use the CppUnit test for the first time. When I try to compile the testing code I get:
testing.cpp:(.text+0xca): undefined reference to
`CppUnit::SourceLine::SourceLine(std::basic_string, std::allocator > const&, int)'
And many other error messages.
I guess that the reason is that compiler does not know what UnitTest library is. Here I found a person asking the same question. I try to use the recommendation from the answers of the linked questions but it still does not work. When I try c++ -lunittest++ testing.cpp I get:
/usr/bin/ld: cannot find -lunittest++
collect2: ld gives back 1 as End-Status
In the make files that are used by others and that work I see: LDLIBS := -lcppunit. So I tried c++ -lcppunit++ testing.cpp but I get the same error message as with the -lunittest.
Does anybody know how I can find location of the UnitTest library and pass this information to the compiler?
This is how I have managed to compile my code:
g++ testing.cpp -lcppunit
I am compiling in netbeans. I added the option -lcppunit in
Properties > Linker > Additional Options
and that let my test files compile and run. Remember to not leave any spaces between options, as that will cause your code to fail to compile
I am new to C++ on linux enviroment and am trying to use the png++ library for a project. The problem I am facing is that that a simple program I write using png++ incudes does not work and shows me the following errors
AProg.o: In function `png::info_base::info_base(png::io_base&, png_struct_def*)':
AProg.cpp:(.text._ZN3png9info_baseC2ERNS_7io_baseEP14png_struct_def[_ZN3png9info_baseC5ERNS_7io_baseEP14png_struct_def]+0x21): undefined reference to `png_create_info_struct'
AProg.o: In function `png::info::write() const':
AProg.cpp:(.text._ZNK3png4info5writeEv[png::info::write() const]+0xd4): undefined reference to `png_set_PLTE'
AProg.cpp:(.text._ZNK3png4info5writeEv[png::info::write() const]+0x137): undefined reference to `png_set_tRNS'
AProg.cpp:(.text._ZNK3png4info5writeEv[png::info::write() const]+0x14f): undefined reference to `png_write_info'
AProg.o: In function `png::info::sync_ihdr() const':
AProg.cpp:(.text._ZNK3png4info9sync_ihdrEv[png::info::sync_ihdr() const]+0x79): undefined reference to `png_set_IHDR'
AProg.o: In function `png::end_info::destroy()':
AProg.cpp:(.text._ZN3png8end_info7destroyEv[png::end_info::destroy()]+0x48): undefined reference to `png_destroy_info_struct'
AProg.o: In function `png::end_info::write() const':
AProg.cpp:(.text._ZNK3png8end_info5writeEv[png::end_info::write() const]+0x1a): undefined reference to `png_write_end'
AProg.o: In function `png::io_base::set_swap() const':
AProg.cpp:(.text._ZNK3png7io_base8set_swapEv[png::io_base::set_swap() const]+0x1b): undefined reference to `png_set_swap'
.............. (and it goes on).
The background of what I have done so far.
1 : I have gcc/g++ configured correctly.
2 : I have correctly installed libpng-1.2.50. The result seems to be correct.
This is how my usr/local folder looks now
:/usr/local/include$ ls
libpng12 libpng15 png++ pngconf.h png.h pnglibconf.h
:/usr/local/lib$ ls
libpng12.a libpng12.so libpng12.so.0.50.0 libpng15.la libpng15.so.15 libpng.a libpng.so libpng.so.3.50.0 python2.7
libpng12.la libpng12.so.0 libpng15.a libpng15.so libpng15.so.15.12.0 libpng.la libpng.so.3 pkgconfig
:/usr/local/bin$ ls
eclipse libpng-1.2.50 libpng12-config libpng-1.5.12 libpng15-config libpng-config png++-0.2.5
3 : After that I followed the following ( http://www.nongnu.org/pngpp/doc/0.2.5/ ) to install the png++-0.2.5 and all the five steps didnt gave any error.
But after that when I tried to compile a simple program (with the instructions given at the same site : http://www.nongnu.org/pngpp/doc/0.2.5/ ) it would not compile.
:~/workspace/AProg$ g++ -o AProg AProg.o 'libpng-config --ldflags'
g++: error: libpng-config --ldflags: No such file or directory
Then I tried to solve the problem and google it and gave this command which seems to work fine at compile but when I tried to run it. I got the error as mentioned at the top of the post
:~/workspace/AProg$ g++ -c AProg.cpp -I/usr/local/include/libpng12 -L/usr/local/lib -lpng -I/usr/local/include/png++
:~/workspace/AProg$
I am sorry for such a long post. But I just wanted to explain anything /everything related to my problem. Hope somebody helps me here.
It seems that the quotes you use in the linker command line is not the correct ones, it should be the single back quote:
$ g++ -o AProg AProg.o `libpng-config --ldflags`
everyone
Recently, I'm working on stereo vision. And I download the StereoMatch code from middlebury website: http://vision.middlebury.edu/stereo/code/
I used Ubuntu 11.10 to run this code. After I run this code, I got the following error. There are 3 'undefined reference to ' error. But the code has already included the header file 'MinFilter.h'. And I get confused. Could someone help me? I would appreciate it.
errors:
StcAggregate.o: In function CStereoMatcher::AggrMin()':
StcAggregate.cpp:(.text+0x20f): undefined reference tovoid MinFilter(CImageOf&, CImageOf&, int, int)'
StcEvaluate.o: In function _ZL14PartialShuffle8CImageOfIhERS0_S1_f.constprop.2':
StcEvaluate.cpp:(.text+0x37): undefined reference tovoid MinFilter(CImageOf&, CImageOf&, int, int)'
StcEvaluate.cpp:(.text+0x5b): undefined reference to `void MaxFilter(CImageOf&, CImageOf&, int, int)'
collect2: ld returned 1 exit status
make: * [StereoMatch] Error 1
This is an error from the linker (and/or runtime environment) which cannot find some symbols (i.e. code) which the header files you've included promised to exist. In order for these symbols to be found, you must tell the linker to link against the library (or object file) containing them. This library may have come with the code pre-compiled or may have been made during installation. Have you not got a README file where it is explained how to use (i.e. link and run) the code?
I met exactly the same problem and solved it like this:
Open the Makefile and change the first line from
CPPFLAGS = -O2 -Wall
to
CPPFLAGS = -O -Wall
Then "make clean" and "make", it works for me. So I guess it is because param
"-O2" does more optimization than expected.