Question

I'm developing applications in C++11 and my compiler is CLang++ 3.3. I'm also using Netbeans 7.3 IDE on Linux Mint 14.

All of my tests are done with GoogleTest (gtest-1.6.0) and almost everything is working fine except the warning mentioned in the title of this post.

Here's the command line executed by netbeans as an example:

clang++ -pedantic-errors -lgtest -pthread   -c -g -Wall -std=c++11 -pedantic-errors -lgtest -pthread -MMD -MP -MF build/Debug/CLang-Linux-x86/_ext/1802678175/main.o.d -o build/Debug/CLang-Linux-x86/_ext/1802678175/main.o ../GIT_CryptoCode/src/main.cpp

I don't know why, but the command contains twice some attributes which gives the same warning twice of course. This is what I did in the project properties : Properties of the project : C++ Compiler If I remove the Additional options, gtest is not working and the command line becomes something like this : clang++ -c -g -Wall -std=c++11 .... What should I do to not get some attributes to be duplicates ?

Well, even with cmake, I got the warning with Clang (which appears once this time :)). I also tested with GCC 4.7 and I didn't get any warning. Here's the command line I use in a cmake file for GCC :

set (CMAKE_CXX_FLAGS                "-Winline -Wall -Werror -pedantic-errors -pthread -std=c++11")

Thus, Clang seems to be the problem. Is anyone know where this warning come from and how to remove it ? Is this a Clang bug ?

Thanks for your help.

Was it helpful?

Solution

I want to thank @Fraser for his help that helps me to find out the way to remove the warnings. Basically, instead of writing -pedantic-errors -lgtest -pthread in the Additional options of the C++ compiler section which gives a duplicate warning, these attributes should be in the Linker section of the project. enter image description here

So, the Additional Options in the C++ compiler section are left empty. Now, I can use the -Werror attribute without any problem.

Also, in the cmake file, the line

target_link_libraries(${Project_Name} ${GTEST_BOTH_LIBRARIES})

links the gtest library to the project. Thus, no need of -lgtest in

set (CMAKE_CXX_FLAGS   "-Winline -Wall -Werror -pedantic-errors -pthread -std=c++11")

both, for GCC and Clang.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top