undefined reference to MinFilter and MaxFilter in StereoMatch code - c++

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.

Related

Cepstral Example Compile Error

I'm trying to build a C++ program that incorporates Cepstral's voice synthesis features. The library was already downloaded on the machine by my predecessor but apparently he never got around to using it. The documentation is pretty much non-existent (there is a single forum that doesn't really have anything helpful). All of their included examples are in C and lack a MakeFile so I'm trying to compile them myself. The little documentation there is simply tells me I need to link to the libswift.so library.
It is a Ubuntu 12.04.5 OS and I tried this compile command
g++ -Wall -g tts.c -o tts -I/opt/swift/include -L/opt/swift/lib -lswift -lm
Which gives this error
/opt/swift/lib/libswift.so: undefined reference to 'sin'
/opt/swift/lib/libswift.so: undefined reference to 'exp'
/opt/swift/lib/libswift.so: undefined reference to 'cos'
/opt/swift/lib/libswift.so: undefined reference to 'log'
/opt/swift/lib/libswift.so: undefined reference to 'pow'
collect2: ld returned 1 exit status
This seems to indicate that -lm is not properly linking for some reason (I also tried switching the order of m and swift for the same result).
I usually use C++ and have very little C experience. I also frequently use Makefiles or edit previous/provided Makefiles and rarely call g++ itself so it's possible I'm missing something fairly obvious. Thanks.

Google RE2 library cannot compile with 'make testinstall' in ubuntu

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.

First CppUnit Test: undefined reference to CppUnit::SourceLine::SourceLine

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

Undefined references in png++

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`

g++ including boost library

i builded my boost library with bjam, and then moved all the .a files into c:\Server\libs\boost_1_46_0\lib
if i want to compile my program there is some error:
the compile command
g++ -Ic:\Server\libs\boost_1_46_0\ -Lc:\Server\libs\boost_1_46_0\lib\ -lboost_thread-mgw45-mt-1_46 -o try1 try1.cpp
the errors
C:\Users\FEHERG~1\AppData\Local\Temp\ccB46To7.o:try1.cpp:(.text+0xe9): undefined
reference to `_imp___ZN5boost6thread4joinEv'
C:\Users\FEHERG~1\AppData\Local\Temp\ccB46To7.o:try1.cpp:(.text+0x120): undefine
d reference to `_imp___ZN5boost6threadD1Ev'
C:\Users\FEHERG~1\AppData\Local\Temp\ccB46To7.o:try1.cpp:(.text+0x138): undefine
d reference to `_imp___ZN5boost6threadD1Ev'
C:\Users\FEHERG~1\AppData\Local\Temp\ccB46To7.o:try1.cpp:(.text$_ZN5boost11this_
thread18interruptible_waitEm[boost::this_thread::interruptible_wait(unsigned lon
g)]+0x40): undefined reference to `_imp___ZN5boost11this_thread18interruptible_w
aitEPvNS_6detail7timeoutE'
C:\Users\FEHERG~1\AppData\Local\Temp\ccB46To7.o:try1.cpp:(.text$_ZN5boost6thread
C1IPFvvEEET_NS_10disable_ifINS_14is_convertibleIRS4_NS_6detail13thread_move_tIS4
_EEEEPNS0_5dummyEE4typeE[boost::thread::thread<void (*)()>(void (*)(), boost::di
sable_if<boost::is_convertible<void (*&)(), boost::detail::thread_move_t<void (*
)()> >, boost::thread::dummy*>::type)]+0x23): undefined reference to `_imp___ZN5
boost6thread12start_threadEv'
collect2: ld returned 1 exit status
can anybody help me what is the problem in this problem?
i followed this tutorial: http://antonym.org/2009/05/threading-with-boost---part-i-creating-threads.html
so this is the source: http://pastebin.com/YqCPLNwU
UPDATE:
i think the error is not lining the library, the error is in the library.
i built it with bjam with toolchain=gcc multithread options.
UPDATE
here is the objdump http://pastebin.com/4fpqYb7d
UPDATE
i found that the problem is that the linker wants to link with dynamic linking or something like this.
Code Blocks, MinGW, Boost, and static linking issues
there "Jack Kelly" says that i need to add #define BOOST_THREAD_USE_LIB at the beginning of my source file. but this not helps to me. how can i link a library statically? (the -static not helped as well)
adding #define BOOST_THREAD_USE_LIB at the beginning works.
Remember to link also boost libs listed in the errors (boost system in my case).
Move the -lboost_thread-mgw45-mt-1_46 option to the end of the command line (after try1.cpp). (From chat.)
This might be relevant https://svn.boost.org/trac/boost/ticket/4614