Eclipse build errors are coming from out-of-date code - c++

I'm running Eclipse 3.7.2 with CDT installed on Ubuntu 12.04.
I created a new C++ project, then added existing source/header files by drag and dropping them into the project explorer. I added the header include paths and source paths to the project settings. The source code I added had a few compiler errors that I fixed. Simple stuff.
My Problem:
For lack of a better explanation, the build error log is showing "ghost" errors; errors that used to exist, but just aren't there anymore. Here's a screenshot showing where it's claiming the errors are in my code. Note: Image is high-resolution. View in separate tab so you can read it!
As you can see, it's complaining about a multiple definition error on line 24. And the code on line 24 has nothing to do with such claims.
Running clean on the project does nothing to help this issue.
Here's the console output for the build.
**** Build of configuration Debug for project blitzAPI ****
make -k all
Building target: blitzAPI
Invoking: GCC C++ Linker
g++ -o "blitzAPI" ./src/blitzAPI.o ./src/function.o ./src/iohelper.o ./src/main.o ./src/strHelper.o
./src/main.o: In function `parseTree(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
/home/david/workspace/blitzAPI/Debug/../src/main.cpp:24: multiple definition of `verbose'
./src/blitzAPI.o:/home/david/workspace/blitzAPI/Debug/../src/blitzAPI.cpp:48: first defined here
./src/main.o: In function `parseTree(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
/home/david/workspace/blitzAPI/Debug/../src/main.cpp:24: multiple definition of `lineCount'
./src/blitzAPI.o:/home/david/workspace/blitzAPI/Debug/../src/blitzAPI.cpp:48: first defined here
./src/main.o: In function `parseTree(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
/home/david/workspace/blitzAPI/Debug/../src/main.cpp:24: multiple definition of `functionList'
./src/blitzAPI.o:/home/david/workspace/blitzAPI/Debug/../src/blitzAPI.cpp:51: first defined here
collect2: ld returned 1 exit status
make: *** [blitzAPI] Error 1
make: Target `all' not remade because of errors.
**** Build Finished ****

Related

Linker errors (library versions conflict)

I have a cmake project which uses conan as its package manager. The project uses boost components of version 1.71 and i have installed libboost-dev (v 1.62) which cannot be deleted from my system.
/usr/bin/ld: warning: libboost_system.so.1.62.0, needed by /usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../x86_64-linux-gnu/libboost_filesystem.so, may conflict with libboost_system.so.1.71.0
/usr/bin/ld: warning: libboost_filesystem.so.1.71.0, needed by bin/libAppUtil.so, may conflict with libboost_filesystem.so.1.62.0
/usr/bin/ld: warning: libboost_filesystem.so.1.71.0, needed by bin/libAppUtil.so, may conflict with libboost_filesystem.so.1.62.0
bin/libCoreInt.so: undefined reference to `boost::filesystem::native(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I don't know if the conflict is a source of linker errors but i guess it is
There are 2 versions of shared library:
libboost_system.so.1.62.0 (already existing )
libboost_system.so.1.71.0 (project requirement)
Since the shared library (libboost_system.so.1.62.0) cannot be deleted. Please upgrade the existing library to libboost_system.so.1.71.0. The issue should be resolved.
But again since there is dependency on libboost_system.so.1.62.0, we
could do the following:
Project specific cmake file should make a reference to directory having the shared library 'libboost_system.so.1.71.0 '.
So when the project is build the executable should point to the version : libboost_system.so.1.71.0.

Errors while trying to compile OpenCV project on Dev C++

Im getting this error:
D:\Users\JF150696\AppData\Local\Temp\ccrDYwyp.o Source2.cpp:(.text+0xdf): undefined reference to `cv::imread(std::string const&, int)'
D:\Users\JF150696\AppData\Local\Temp\ccrDYwyp.o Source2.cpp:(.text+0xdec): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
D:\Users\JF150696\AppData\Local\Temp\ccrDYwyp.o Source2.cpp:(.text+0xe41): undefined reference to `cv::imwrite(std::string const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)'
d:\devc\dev-cpp\mingw64\x86_64-w64-mingw32\bin\ld.exe D:\Users\JF150696\AppData\Local\Temp\ccrDYwyp.o: bad reloc address 0x20 in section `.text$_ZSt4sqrtf[__ZSt4sqrtf]'
D:\devc\opencv\projekty\test 3 opencv\test 3 opencv\collect2.exe [Error] ld returned 1 exit status
What i did in Dev Options:
I have added this command line to compiler:
-L"C:\opencv\build\x86\vc11\lib" -lopencv_highgui248 -lopencv_core248 -lopencv_imgproc248 -lopencv_calib3d248 -lopencv_video248 -lopencv_features2d248 -lopencv_ml248 -lopencv_highgui248 -lopencv_objdetect248 -lopencv_contrib248 -lopencv_legacy248 -lopencv_flann248
This lane to linker options:
-static-libgcc -lopencv_highgui248 -lopencv_core248 -lopencv_imgproc248 -lopencv_calib3d248 -lopencv_video248 -lopencv_features2d248 -lopencv_ml248 -lopencv_highgui248 -lopencv_objdetect248 -lopencv_contrib248 -lopencv_legacy248 -lopencv_flann248
In directiories i have added:
binaries: D:\devc\opencv\build\x86\vc11\bin
libs: D:\devc\opencv\build\x86\vc11\lib
headers C: D:\devc\opencv\build\include\opencv2 D:\devc\opencv\build\include\opencv D:\devc\opencv\build\include
headers C++: same as above
I have added opencv path D:\devc\opencv to PATH variable
My dev C++ version is: 5.7.0, OpenCV: 2.4.8
Anyone know how to fix that?
EDIT
Same problem using CodeBlock
Did you link Source2 to collect2 properly? Source2.cpp should be compiled into an object file before linking with your main program.
If I am not mistaken, the problems are not related to linking libraries it is because imread and imwrite shouldnt be like you called
imread(string, mat)
But you called
imread(string, int)
So it gives error. Same with other lines.
Build the libraries using CMake and CodeBlocks as given in here till step 3 of codeblock settings.
Then include the following as given in the blog to Devc++ C and C++ Includes tab
C:\OpenCV\my_build\install\include
C:\OpenCV\my_build\install\include\opencv
C:\OpenCV\my_build\install\include\opencv2
since you have included opencv and opencv2, remove /opencv2/..and /opencv ..in the header files.
and add the below line to libraries in Devc++
C:\OpenCV\my_build\install\x64\mingw\lib
also add all the .dll.a files in C:\OpenCV\my_build\install\x64\mingw\lib to Project Options.
Copy all the dll files from opencv\my_build\install\x64\mingw\bin and paste to folder where EXE of your program would be built.

Can't get googletest running with ubuntu (linker errors)

I've built googletest using make under linux, the resulting files are libgtest.a libgtest_main.a.
I referenced the include files from my application and added the following lib dependencies (in the given order):
-lgtest
-lpthread
However I get the following two linker errors when I try to compile:
more undefined references to `testing::internal::EqFailure(char const*, char const*, testing::internal::String const&, testing::internal::String const&, bool)
undefined reference to `testing::internal::String::ShowCStringQuoted(char const*)
From what I've seen within the googletest source, the EqFailure function is directly implemented within gtest.cc. I don't understand why I should get a linker error here, the other definitions from googletest could obviously also be found (if I remove -lgtest, I get alot of more linker errors).
What am I missing? Thank you in advance.
Make sure you do not accidentally mix your own gtest and the one shipped with ubuntu.
I use cmake to build and got the same errors due to cmake opting for /usr/include over my own custom built version (which is what I linked with).

trouble linking cpp/hpp from cmake

There's zillions of questions on this, but nothing I have read has helped me to resolve my problem.
I am working on unit testing on a large project, so there are multiple CMakeLists.txt files. I created a "utilities.cpp" file which grew quickly, so I decided to split it into test_utilities.cpp and test_utilities.hpp. When I #include test_utilities.cpp there is joy, but if I #include test_utilities.hpp the build fails:
Linking CXX executable foo
CMakeFiles/foo.dir/src/foo.cpp.o: In function `foo::bar()':
/mydir/trunk/tests/src/foo.cpp:57: undefined reference to `exit_on_invalid_config(std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&)'
collect2: ld returned 1 exit status
make[2]: *** [tests/foo] Error 1
make[1]: *** [tests/CMakeFiles/foo.dir/all] Error 2
make: *** [all] Error 2
I think this is because the hpp and cpp are not being linked.
I have tried adding this to CMakeLists.txt:
ADD_EXECUTABLE(utilities src/test_utilities.cpp src/test_utilities.hpp)
TARGET_LINK_LIBRARIES(utilities
some_project
test_main
boost_program_options)
(actually this was here before, minus the hpp part, when I was including utilities.cpp, before I added the header file). This change does not help, so I tried adding
ADD_LIBRARY(test_utilities src/test_utilities.cpp src/test_utilities.hpp)
and included test_utilities into TARGET_LINK_LIBRARIES:
ADD_EXECUTABLE(foo src/foo.cpp)
TARGET_LINK_LIBRARIES(foo
some_project
test_main
test_utilities
boost_program_options)
But when I try this, I get errors about boost crap being redefined. When I remove boost imports from foo.cpp, test_utilities.cpp/hpp I either get the same output or complaints that it can't find boost definitions.
What I would like CMake to do is compile the test_utilities executable (cpp + hpp) so that I don't get undefined reference when I try to import test_utilities.hpp from foo.cpp.
Thanks in advance for your help.
Edit: another issue I am having is, I'll add the executable test_utilities, but it doesn't get built before foo. I feel like this is part of my problem and I haven't figured out how to get test_utilities to build first.
Edit: Resolved thanks to wojciii! My issue boiled down to, I was importing boost unit test in test_utilities.cpp, test_main.cpp, and foo.cpp. I needed to stop doing that, fix dependency issues in my hpp, and tweak CMakeLists.txt a little.

How do I set up gtest in Windows Netbeans?

I've looked at the Netbeans forums, gtest wiki & around here & I can't seem to find a way to get gtest working right in Netbeans (6.9.1, Windows 7x64). There's no problem with my #include of gtest.h or with the unittest file itself - ASSERT_LE is recognized etc. I'm using cygwin & the results are the same with gtest at c:\gtest-1.5.0 or cygwin/usr/local/gtest-1.5.0. I think it might be matter of getting a different makefile for the tests to use & based off the gtest included makefile, but that hasn't worked for me (maybe I'm doing it wrong). This is what I get when I hit ALT-F6 (Test Project):
g++.exe -o build/Debug/Cygwin-Windows/tests/TestFiles/f1 build/Debug/Cygwin-Windows/tests/tests/Armor_unittest.o build/Debug/Cygwin-Windows/tests/tests/newsimpletest.o build/Debug/Cygwin-Windows/main_nomain.o build/Debug/Cygwin-Windows/Character_nomain.o build/Debug/Cygwin-Windows/Map_nomain.o build/Debug/Cygwin-Windows/Armor_nomain.o build/Debug/Cygwin-Windows/Weapon_nomain.o build/Debug/Cygwin-Windows/Shop_nomain.o build/Debug/Cygwin-Windows/Enemy_nomain.o
build/Debug/Cygwin-Windows/tests/tests/Armor_unittest.o: In function `_ZN31ArmorTest_SetupAndGetWorks_Test8TestBodyEv':
/cygdrive/c/Users/.../winPro2Game/tests/Armor_unittest.cpp:9: undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
/cygdrive/c/Users/.../winPro2Game/tests/Armor_unittest.cpp:9: undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
/cygdrive/c/Users/.../winPro2Game/tests/Armor_unittest.cpp:9: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/cygdrive/c/Users/.../winPro2Game/tests/Armor_unittest.cpp:9: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
etc...
If I put a custom built makefile that is almost identical to the one included with gtest into the test folder & right click on it & Make I get:
Makefile:21: target `gtest-all.o' doesn't match the target pattern
Makefile:25: target `gtest_main.o' doesn't match the target pattern
Makefile:39: *** multiple target patterns. Stop.
If I do Test Project again I get:
rm -f build/Debug/Cygwin-Windows/tests/tests/Makefile.o.d
g++.exe -c -g -I../../../../../../../gtest-1.5.0/include -MMD -MP -MF build/Debug/Cygwin-Windows/tests/tests/Makefile.o.d -o build/Debug/Cygwin-Windows/tests/tests/Makefile.o tests/Makefile
g++: tests/Makefile: linker input file unused because linking not done
gcc.exe build/Debug/Cygwin-Windows/tests/tests/Makefile.o -o build/Debug/Cygwin-Windows/tests/tests/Makefile
gcc: build/Debug/Cygwin-Windows/tests/tests/Makefile.o: No such file or directory
gcc: no input files
make[1]: *** [build/Debug/Cygwin-Windows/tests/tests/Makefile] Error 1
make[1]: Leaving directory `/cygdrive/c/Users/.../winPro2Game'
make: *** [.build-tests-impl] Error 2
Thanks!
you were close in the first place - from the first snippet of "undefined reference", it's a linker configuration issue - you don't have gtest library added. as far as i remember, gtest doesn't ship binaries, so you'll have to compile library yourself (gtest.lib), then add that somewhere in linker properties as additional library - not a netbeans user myself, can't tell exactly where.