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.
Related
I'm making a C++ program available under Linux, Mac and Windows environments, respectively.
It uses GiNaC library.
It works fine under Linux and Mac environment.
However, I failed to build it under Windows environment.
I used precompiled GiNaC files including header, library and executable files downloaded from http://theor.jinr.ru/~varg/web/proj/ginac/woe32/ .
The following is the console message, and bold text represents the error message.
08:19:09 **** Incremental Build of configuration Debug for project
metapro **** Info: Configuration "Debug" uses tool-chain "MinGW GCC"
that is unsupported on this system, attempting to build anyway. Info:
Internal Builder is used for build g++
"-LC:\Users\yoons\Documents\ginac-1.4.4-cln-1.2.2-2587288a-gmp-4.2.4-i586-mingw32msvc\opt\ginac\lib\"
"-LC:\vcpkg\packages\gsl_x86-windows\lib"
"-LC:\Users\yoons\Documents\boost_1_70_0\stage\lib" -o
myproject.exe a.o b.o main.o c.o d.o e.o -lginac
-lm -lgsl -lgslcblas c.o: In function `Z7ordmetaSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EEPPdS9_iiiS5_':
C:\Users\yoons\eclipse-workspace\metapro\Debug/../c.cpp:53:
undefined reference to
`GiNaC::symbol::symbol(std::__cxx11::basic_string, std::allocator > const&, unsigned int)'
collect2.exe: error: ld returned 1 exit status
08:19:10 Build Failed. 1 errors, 0 warnings. (took 1s.221ms)
A strange thing is that the error occurred only 'symbol' type not others such as 'ex' or other functions provided by GiNaC package.
If anyone knows the answer, please let me know.
Sora
I have a Qt5 C++ program and I'm trying to link to a static library. The static library is senselock/libsenseEIV.a (relative to the main.cpp file). When I compile I see the output below:
^
g++ -Wl,-rpath,/opt/Qt/5.7/gcc_64/lib -o test1 main.o -Lsenselock/libsenseEIV.a -L/opt/Qt/5.7/gcc_64/lib -lQt5Core -lpthread
main.o: In function `test1()':
/test1/main.cpp:31: undefined reference to `S4Enum'
/test1/main.cpp:58: undefined reference to `S4Enum'
/test1/main.cpp:71: undefined reference to `S4Open'
/test1/main.cpp:83: undefined reference to `S4Control'
/test1/main.cpp:102: undefined reference to `S4Close'
collect2: error: ld returned 1 exit status
make: *** [Makefile:216: test1] Error 1
11:55:27: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project test1 (kit: Desktop Qt 5.7.1 GCC 64bit)
When executing step "Make"
and in my .pro file I have
LIBS += -Lsenselock/libsenseEIV.a
in case that matters. Can someone explain how to fix this error? The undefined reference errors all relate to functions located in that libsenseEIV.a library.
I don't understand if the compiler can't find the .a file or there's some other error.
UPDATE: I tried this syntax
LIBS += -Lsenselock -lsenseEIV
but it generates error
/usr/bin/ld: cannot find -lsenseEIV
Am I using the wrong library name? If so how would I find the name? (assuming this is compiled into the .a file)
This part of your command line is wrong:
-Lsenselock/libsenseEIV.a
Should be:
senselock/libsenseEIV.a
(The -Lfoo/bar.a tells linker to search directory foo/bar.a/ for libraries, which is not at all what you want.)
No -l prefix?
You can specify linking with libsenseEIV.a in the following (mostly equivalent) ways:
senselock/libsenseEIV.a
-Lsenselock -lsenseEIV
-Lsenselock -l:libsenseEIV.a
You're using the linker flags wrong, you should specify the library path after -L and the library name after -l. In other words you need to have both in the assignment to LIBS variable in your .pro file.
After all it turns out that you can use LIBS += -L$$PWD/senselock/ -lsenseEIV for your case
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.
I have the problem that as the g++ tries to link the object files I receive the following error:
11:29:13 **** Build of configuration Debug for project daytime ****
make all
'Building target: daytime'
'Invoking: Cross G++ Linker'
g++ -o "daytime" ./tcf/services/daytime.o ./tcf/main/main.o
./tcf/services/daytime.o: In function `command_get_time_of_day':
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:38: undefined reference to `json_read_string'
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:40: undefined reference to `exception'
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:43: undefined reference to `exception'
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:52: undefined reference to `write_stringz'
makefile:46: recipe for target 'daytime' failed
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:54: undefined reference to `write_stringz'
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:56: undefined reference to `write_errno'
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:58: undefined reference to `json_write_string'
./tcf/services/daytime.o: In function `ini_daytime_service':
C:\Users\falkstef\runtime-EclipseApplication\daytime\Debug/../tcf/services/daytime.c:70: undefined reference to `add_command_handler'
collect2.exe: error: ld returned 1 exit status
make: *** [daytime] Error 1
I have no idea why this is the case since e.g. #include <tcf/framework/json.h>is included and found.
Didn't gcc compile the corresponding *.c files such that this linker error occurs?
What is the problem here?
Thank you.
It is not enough to include the header files; you also have to specify the libraries where those functions are defined.
To make the linker find all those methods/classes (json_read_string, write_stringz, exception) you need to reference the library. If e.g. they are contained in a library called libjson.so, you should do:
g++ -ljson -o "daytime" ./tcf/services/daytime.o ./tcf/main/main.o
(or add the library to the project options, if eclipse is managing your make files).
Or if it's another .o file, include that in the compilation (-> or in the project, if eclipse is creating the make file).
I am trying to use Sqlite in my Netbeans C++ and following the tutorial here
http://www.dreamincode.net/forums/topic/122300-sqlite-in-c/
When i build it,its giving me undefined reference to `sqlite3_open' and the other sqlite3 functions. I included the sqlite3.h too. What am i missing here?
When i added the linker to static library libsqlite3.a in project properties, my undefined reference errors are gone but now its giving me
/usr/lib/libsqlite3.a(sqlite3.o): In function pthreadMutexTry':
/usr/lib/libsqlite3.a(sqlite3.o): In functionpthreadMutexAlloc':
/usr/lib/libsqlite3.a(sqlite3.o): In function pthreadMutexAlloc':
/usr/lib/libsqlite3.a(sqlite3.o): In functionpthreadMutexAlloc':
/usr/lib/libsqlite3.a(sqlite3.o): In function unixDlError':
/usr/lib/libsqlite3.a(sqlite3.o): In functionfindLockInfo':
/usr/lib/libsqlite3.a(sqlite3.o): In function findLockInfo':
/usr/lib/libsqlite3.a(sqlite3.o): In functionunixDlSym':
/usr/lib/libsqlite3.a(sqlite3.o): In function unixDlClose':
/usr/lib/libsqlite3.a(sqlite3.o): In functionunixDlOpen':
collect2: ld returned 1 exit status
make[2]: * [dist/Debug/GNU-Linux-x86/cddb] Error 1
make[1]: * [.build-conf] Error 2
make: *** [.build-impl] Error 2
And if i include the sqlite3ext.h, I get
main.cpp:20: error: ‘sqlite3_api’ was not declared in this scope
(please see EDIT below)
Not sure how C++ works in NetBeans, but your adding libsqlite3.a looks pretty good. Now if you have a Makefile you could edit it and define (or edit) the LDFLAGS variable, and pass it as an option to the linker...
SQLite in its default configuration needs to link with libdl and libpthread, that is why you might need to add -ldl -lpthread to your linking options.
For instance (if this is possible in NetBeans) add this to your Makefile :
LDFLAGS= -ldl -lpthread
In my projects I use it like so :
target: $(OBJ)
gcc $(LDFLAGS) $(OBJ) -o $#
EDIT :
Actually it is also possible to add linker options in the GUI, without editing the Makefile by hand :
In submenu Configuration Properties -> Linker -> Command Line, just add -ldl -lpthread in "Additional options" and recompile your project.
Integrating Sqlite into Netbeans on Linux
1)Synaptic Package Manager - Install libsqlite3-dev
2)Netbeans->Your_Project Properties->Linker->Libraries->Add Library-> libsqlite3.a
3)#include sqlite3.h
It works!