QT Creator CMakeLists.txt c++ link errors -


note: have updated original post simplify, clarify, , reflect things have tried, including adopting suggestions comments.

i running qt creator 4.2.1 , trying compile c++ project defined cmakelists.txt. program compiles fine command line cmake . && make. work qt creator ide.

i have 2 ubuntu machines. 1 process works fine, 1 fails. on machine fails, if open cmakelists.txt project in qt , try compile, fails compile many linker errors. how can fix this?

here things have tried

  • uninstall , reinstall qt creator
  • uninstall , reinstall build-essential
  • including various lib paths in may makefile
  • enabling , disabling system environment variables in qt project
  • changing qt kit use clang. works, understand why gcc isn't working.

i looking hard environmental differences can't figure out causing problem.

main.cpp:

#include <iostream>   int main(int argc, char *argv[]) {   std::cout << "hello, qt!" << std::endl; } 

cmakelists.txt:

project(example) cmake_minimum_required(version 2.8) add_executable(example main.cpp) 

compile output

08:42:09: running steps project example... 08:42:09: starting: "/usr/bin/cmake" --build . --target -- verbose=1 /usr/bin/cmake -h/home/brian/example -b/home/brian/build-example-desktop_qt_5_8_0_gcc_64bit-debug --check-build-system cmakefiles/makefile.cmake 0 /usr/bin/cmake -e cmake_progress_start /home/brian/build-example-desktop_qt_5_8_0_gcc_64bit-debug/cmakefiles /home/brian/build-example-desktop_qt_5_8_0_gcc_64bit-debug/cmakefiles/progress.marks /usr/bin/make -f cmakefiles/makefile2 make[1]: entering directory '/home/brian/build-example-desktop_qt_5_8_0_gcc_64bit-debug' /usr/bin/make -f cmakefiles/example.dir/build.make cmakefiles/example.dir/depend make[2]: entering directory '/home/brian/build-example-desktop_qt_5_8_0_gcc_64bit-debug' cd /home/brian/build-example-desktop_qt_5_8_0_gcc_64bit-debug && /usr/bin/cmake -e cmake_depends "unix makefiles" /home/brian/example /home/brian/example /home/brian/build-example-desktop_qt_5_8_0_gcc_64bit-debug /home/brian/build-example-desktop_qt_5_8_0_gcc_64bit-debug /home/brian/build-example-desktop_qt_5_8_0_gcc_64bit-debug/cmakefiles/example.dir/dependinfo.cmake --color= make[2]: leaving directory '/home/brian/build-example-desktop_qt_5_8_0_gcc_64bit-debug' /usr/bin/make -f cmakefiles/example.dir/build.make cmakefiles/example.dir/build make[2]: entering directory '/home/brian/build-example-desktop_qt_5_8_0_gcc_64bit-debug' [ 50%] building cxx object cmakefiles/example.dir/main.cpp.o /usr/bin/gcc     -g   -o cmakefiles/example.dir/main.cpp.o -c /home/brian/example/main.cpp [100%] linking cxx executable example /usr/bin/cmake -e cmake_link_script cmakefiles/example.dir/link.txt --verbose=1 /usr/bin/gcc   -g   cmakefiles/example.dir/main.cpp.o  -o example -rdynamic  cmakefiles/example.dir/main.cpp.o: in function `main': /home/brian/example/main.cpp:6: undefined reference `std::cout' /home/brian/example/main.cpp:6: undefined reference `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' /home/brian/example/main.cpp:6: undefined reference `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)' cmakefiles/example.dir/build.make:94: recipe target 'example' failed make[2]: leaving directory '/home/brian/build-example-desktop_qt_5_8_0_gcc_64bit-debug' cmakefiles/makefile2:67: recipe target 'cmakefiles/example.dir/all' failed make[1]: leaving directory '/home/brian/build-example-desktop_qt_5_8_0_gcc_64bit-debug' makefile:83: recipe target 'all' failed /home/brian/example/main.cpp:6: undefined reference `std::ostream::operator<<(std::ostream& (*)(std::ostream&))' cmakefiles/example.dir/main.cpp.o: in function `__static_initialization_and_destruction_0(int, int)': /usr/include/c++/6/iostream:74: undefined reference `std::ios_base::init::init()' /usr/include/c++/6/iostream:74: undefined reference `std::ios_base::init::~init()' collect2: error: ld returned 1 exit status make[2]: *** [example] error 1 make[1]: *** [cmakefiles/example.dir/all] error 2 make: *** [all] error 2 08:42:09: process "/usr/bin/cmake" exited code 2. error while building/deploying project example (kit: desktop qt 5.8.0 gcc 64bit) when executing step "make" 08:42:09: elapsed time: 00:00. 

it seems qt creator not set right. using cmake build system in project, uses various environment variables (useful list , description here: https://cmake.org/wiki/cmake_useful_variables).

when set compiler (or may done automatically during install, previous versions forgotten config files, etc.) in qtcreator settings (eg. see here qt creator use gcc version located in place), environment variables project set according qtcreator settings. may difference when compiling project directly. reset correct compiler path (eg. /usr/bin/g++).

you can add output of cmake variables (eg. see howto cmake: print out accessible variables in script) , try compile projects manually , in qtcreator. output get, difference should obvious. pay attention cmake_cxx_compiler variable.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -