make errors in Qt Creator different to the command line make
-
I'm trying to build the Protobuf tutorial on Ubuntu and ran into the following
[cmake] Running /home/llist/Qt/Tools/CMake/bin/cmake -S /home/llist/QtProjects/ProtobuffTutorial -B /home/llist/QtProjects/build-ProtobuffTutorial-Desktop_Qt_6_6_1_GCC_64bit-Debug in /home/llist/QtProjects/build-ProtobuffTutorial-Desktop_Qt_6_6_1_GCC_64bit-Debug. [cmake] -- Configuring done (0.1s) [cmake] -- Generating done (0.0s) [cmake] -- Build files have been written to: /home/llist/QtProjects/build-ProtobuffTutorial-Desktop_Qt_6_6_1_GCC_64bit-Debug [cmake] [cmake] Elapsed time: 00:00. [cmake] Running /home/llist/Qt/Tools/CMake/bin/cmake -S /home/llist/QtProjects/ProtobuffTutorial -B /home/llist/QtProjects/build-ProtobuffTutorial-Desktop_Qt_6_6_1_GCC_64bit-Debug -DCMAKE_GENERATOR:STRING=Ninja -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=/home/llist/QtProjects/build-ProtobuffTutorial-Desktop_Qt_6_6_1_GCC_64bit-Debug/.qtc/package-manager/auto-setup.cmake -DQT_QMAKE_EXECUTABLE:FILEPATH=/home/llist/Qt/6.6.1/gcc_64/bin/qmake -DCMAKE_PREFIX_PATH:PATH=/home/llist/Qt/6.6.1/gcc_64 -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/gcc-12 -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/x86_64-linux-gnu-g++ -DCMAKE_CXX_FLAGS_INIT:STRING=-DQT_QML_DEBUG in /home/llist/QtProjects/build-ProtobuffTutorial-Desktop_Qt_6_6_1_GCC_64bit-Debug. [cmake] -- The CXX compiler identification is GNU 11.4.0 [cmake] -- Detecting CXX compiler ABI info [cmake] -- Detecting CXX compiler ABI info - done [cmake] -- Check for working CXX compiler: /usr/bin/x86_64-linux-gnu-g++ - skipped [cmake] -- Detecting CXX compile features [cmake] -- Detecting CXX compile features - done [cmake] -- Performing Test CMAKE_HAVE_LIBC_PTHREAD [cmake] -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success [cmake] -- Found Threads: TRUE [cmake] -- Performing Test HAVE_STDATOMIC [cmake] -- Performing Test HAVE_STDATOMIC - Success [cmake] -- Found WrapAtomic: TRUE [cmake] -- Found Protobuf: /usr/lib/x86_64-linux-gnu/libprotobuf.so (found version "3.12.4") [cmake] -- Configuring done (0.3s) [cmake] -- Generating done (0.0s) [cmake] -- Build files have been written to: /home/llist/QtProjects/build-ProtobuffTutorial-Desktop_Qt_6_6_1_GCC_64bit-Debug [cmake] [cmake] Elapsed time: 00:00. ------------------------------------------
Command line
-- The CXX compiler identification is GNU 11.4.0 -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Looking for C++ include pthread.h -- Looking for C++ include pthread.h - found -- Performing Test CMAKE_HAVE_LIBC_PTHREAD -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success -- Found Threads: TRUE -- Performing Test HAVE_STDATOMIC -- Performing Test HAVE_STDATOMIC - Success -- Found WrapAtomic: TRUE -- Found Protobuf: /usr/lib/x86_64-linux-gnu/libprotobuf.so (found version "3.12.4") -- Configuring done -- Generating done -- Build files have been written to: /home/llist/QtProjects/ProtobuffTutorial/build
In Qt Creator I get the following errors when compiling
17:21:26: Running steps for project ProtobuffTutorial... 17:21:26: Starting: "/home/llist/Qt/Tools/CMake/bin/cmake" --build /home/llist/QtProjects/build-ProtobuffTutorial-Desktop_Qt_6_6_1_GCC_64bit-Debug --target all [1/1 8.9/sec] Linking CXX executable ProtobuffTutorial FAILED: ProtobuffTutorial : && /usr/bin/x86_64-linux-gnu-g++ -DQT_QML_DEBUG -g CMakeFiles/ProtobuffTutorial.dir/ProtobuffTutorial_autogen/mocs_compilation.cpp.o CMakeFiles/ProtobuffTutorial.dir/main.cpp.o -o ProtobuffTutorial -Wl,-rpath,/home/llist/Qt/6.6.1/gcc_64/lib: /home/llist/Qt/6.6.1/gcc_64/lib/libQt6Core.so.6.6.1 && : /usr/bin/ld: CMakeFiles/ProtobuffTutorial.dir/main.cpp.o: in function `PromptForAddress(tutorial::Person*)': /home/llist/QtProjects/ProtobuffTutorial/main.cpp:56: undefined reference to `google::protobuf::util::TimeUtil::SecondsToTimestamp(long)' /usr/bin/ld: /home/llist/QtProjects/ProtobuffTutorial/main.cpp:56: undefined reference to `google::protobuf::Timestamp::~Timestamp()' /usr/bin/ld: /home/llist/QtProjects/ProtobuffTutorial/main.cpp:56: undefined reference to `google::protobuf::Timestamp::~Timestamp()' /usr/bin/ld: CMakeFiles/ProtobuffTutorial.dir/main.cpp.o: in function `main': /home/llist/QtProjects/ProtobuffTutorial/main.cpp:75: undefined reference to `google::protobuf::MessageLite::ParseFromIstream(std::istream*)' /usr/bin/ld: /home/llist/QtProjects/ProtobuffTutorial/main.cpp:87: undefined reference to `google::protobuf::MessageLite::SerializeToOstream(std::ostream*) const' /usr/bin/ld: /home/llist/QtProjects/ProtobuffTutorial/main.cpp:93: undefined reference to `tutorial::AddressBook::~AddressBook()' /usr/bin/ld: /home/llist/QtProjects/ProtobuffTutorial/main.cpp:93: undefined reference to `tutorial::AddressBook::~AddressBook()' /usr/bin/ld: CMakeFiles/ProtobuffTutorial.dir/main.cpp.o: in function `google::protobuf::Arena::AllocHook(std::type_info const*, unsigned long) const': /usr/include/google/protobuf/arena.h:522: undefined reference to `google::protobuf::Arena::OnArenaAllocation(std::type_info const*, unsigned long) const' /usr/bin/ld: CMakeFiles/ProtobuffTutorial.dir/main.cpp.o: in function `google::protobuf::internal::ArenaStringPtr::CreateInstance(google::protobuf::Arena*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const*)': /usr/include/google/protobuf/arenastring.h:371: undefined reference to `google::protobuf::internal::LogMessage::LogMessage(google::protobuf::LogLevel, char const*, int)' /usr/bin/ld: /usr/include/google/protobuf/arenastring.h:371: undefined reference to `google::protobuf::internal::LogMessage::operator<<(char const*)' /usr/bin/ld: /usr/include/google/protobuf/arenastring.h:371: undefined reference to `google::protobuf::internal::LogFinisher::operator=(google::protobuf::internal::LogMessage&)' /usr/bin/ld: /usr/include/google/protobuf/arenastring.h:371: undefined reference to `google::protobuf::internal::LogMessage::~LogMessage()' /usr/bin/ld: CMakeFiles/ProtobuffTutorial.dir/main.cpp.o: in function `void* google::protobuf::Arena::AllocateInternal<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(bool)': /usr/include/google/protobuf/arena.h:536: undefined reference to `google::protobuf::Arena::AllocateAlignedNoHook(unsigned long)' /usr/bin/ld: /usr/include/google/protobuf/arena.h:538: undefined reference to `google::protobuf::internal::ArenaImpl::AllocateAlignedAndAddCleanup(unsigned long, void (*)(void*))' /usr/bin/ld: CMakeFiles/ProtobuffTutorial.dir/main.cpp.o: in function `google::protobuf::internal::ArenaStringPtr::CreateInstance(google::protobuf::Arena*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const*)': /usr/include/google/protobuf/arenastring.h:371: undefined reference to `google::protobuf::internal::LogMessage::~LogMessage()' /usr/bin/ld: CMakeFiles/ProtobuffTutorial.dir/main.cpp.o: in function `google::protobuf::internal::GetEmptyStringAlreadyInited[abi:cxx11]()': /usr/include/google/protobuf/message_lite.h:155: undefined reference to `google::protobuf::internal::fixed_address_empty_string[abi:cxx11]' /usr/bin/ld: CMakeFiles/ProtobuffTutorial.dir/main.cpp.o: in function `google::protobuf::Timestamp::operator=(google::protobuf::Timestamp&&)': /usr/include/google/protobuf/timestamp.pb.h:87: undefined reference to `google::protobuf::Timestamp::InternalSwap(google::protobuf::Timestamp*)' /usr/bin/ld: /usr/include/google/protobuf/timestamp.pb.h:89: undefined reference to `google::protobuf::Timestamp::CopyFrom(google::protobuf::Timestamp const&)' /usr/bin/ld: CMakeFiles/ProtobuffTutorial.dir/main.cpp.o: in function `tutorial::AddressBook::AddressBook()': /home/llist/QtProjects/build-ProtobuffTutorial-Desktop_Qt_6_6_1_GCC_64bit-Debug/proto/message.pb.h:537: undefined reference to `tutorial::AddressBook::AddressBook(google::protobuf::Arena*)' /usr/bin/ld: CMakeFiles/ProtobuffTutorial.dir/main.cpp.o: in function `google::protobuf::Timestamp* google::protobuf::MessageLite::CreateMaybeMessage<google::protobuf::Timestamp>(google::protobuf::Arena*)': /usr/include/google/protobuf/message_lite.h:450: undefined reference to `google::protobuf::Timestamp* google::protobuf::Arena::CreateMaybeMessage<google::protobuf::Timestamp>(google::protobuf::Arena*)' /usr/bin/ld: CMakeFiles/ProtobuffTutorial.dir/main.cpp.o: in function `google::protobuf::RepeatedPtrField<tutorial::Person_PhoneNumber>::TypeHandler::Type* google::protobuf::internal::RepeatedPtrFieldBase::Add<google::protobuf::RepeatedPtrField<tutorial::Person_PhoneNumber>::TypeHandler>(google::protobuf::RepeatedPtrField<tutorial::Person_PhoneNumber>::TypeHandler::Type*)': /usr/include/google/protobuf/repeated_field.h:1734: undefined reference to `google::protobuf::internal::RepeatedPtrFieldBase::Reserve(int)' /usr/bin/ld: CMakeFiles/ProtobuffTutorial.dir/main.cpp.o: in function `google::protobuf::RepeatedPtrField<tutorial::Person>::TypeHandler::Type* google::protobuf::internal::RepeatedPtrFieldBase::Add<google::protobuf::RepeatedPtrField<tutorial::Person>::TypeHandler>(google::protobuf::RepeatedPtrField<tutorial::Person>::TypeHandler::Type*)': /usr/include/google/protobuf/repeated_field.h:1734: undefined reference to `google::protobuf::internal::RepeatedPtrFieldBase::Reserve(int)' /usr/bin/ld: CMakeFiles/ProtobuffTutorial.dir/main.cpp.o: in function `google::protobuf::internal::GenericTypeHandler<tutorial::Person_PhoneNumber>::New(google::protobuf::Arena*)': /usr/include/google/protobuf/repeated_field.h:802: undefined reference to `tutorial::Person_PhoneNumber* google::protobuf::Arena::CreateMaybeMessage<tutorial::Person_PhoneNumber>(google::protobuf::Arena*)' /usr/bin/ld: CMakeFiles/ProtobuffTutorial.dir/main.cpp.o: in function `google::protobuf::internal::GenericTypeHandler<tutorial::Person>::New(google::protobuf::Arena*)': /usr/include/google/protobuf/repeated_field.h:802: undefined reference to `tutorial::Person* google::protobuf::Arena::CreateMaybeMessage<tutorial::Person>(google::protobuf::Arena*)' collect2: error: ld returned 1 exit status ninja: build stopped: subcommand failed. 17:21:26: The process "/home/llist/Qt/Tools/CMake/bin/cmake" exited with code 1. Error while building/deploying project ProtobuffTutorial (kit: Desktop Qt 6.6.1 GCC 64bit) When executing step "Build" 17:21:26: Elapsed time: 00:00.
On the command line I get this
llist@poldis:~/QtProjects/ProtobuffTutorial/build$ make [ 10%] Automatic MOC and UIC for target ProtobuffTutorial [ 10%] Built target ProtobuffTutorial_autogen [ 20%] Building CXX object CMakeFiles/ProtobuffTutorial.dir/ProtobuffTutorial_autogen/mocs_compilation.cpp.o [ 30%] Building CXX object CMakeFiles/ProtobuffTutorial.dir/main.cpp.o /home/llist/QtProjects/ProtobuffTutorial/main.cpp:8:10: fatal error: proto/message.pb.h: No such file or directory 8 | #include "proto/message.pb.h" | ^~~~~~~~~~~~~~~~~~~~ compilation terminated. make[2]: *** [CMakeFiles/ProtobuffTutorial.dir/build.make:90: CMakeFiles/ProtobuffTutorial.dir/main.cpp.o] Error 1 make[1]: *** [CMakeFiles/Makefile2:102: CMakeFiles/ProtobuffTutorial.dir/all] Error 2 make: *** [Makefile:136: all] Error 2
The two cmake files involved are pretty simple
root
cmake_minimum_required(VERSION 3.14) project(ProtobuffTutorial LANGUAGES CXX) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core) add_subdirectory(proto) add_executable(ProtobuffTutorial main.cpp ) target_include_directories(ProtobuffTutorial PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") target_link_libraries(ProtobuffTutorial Qt${QT_VERSION_MAJOR}::Core ) include(GNUInstallDirs) install(TARGETS ProtobuffTutorial LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
proto
INCLUDE(FindProtobuf) FIND_PACKAGE(Protobuf REQUIRED) include_directories(${Protobuf_INCLUDE_DIR}) protobuf_generate_cpp(PROTO_SRC PROTO_HEADER message.proto) ADD_LIBRARY(proto ${PROTO_HEADER} ${PROTO_SRC} ) target_sources (proto PRIVATE message.proto ) include_directories(${CMAKE_CURRENT_BINARY_DIR}) target_include_directories(proto PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
I don't know why the two compiles are different and I also don't know why I get the google issues within Qt Creator.
Thanks
-
@Poldi said in make errors in Qt Creator different to the command line make:
I don't know why the two compiles are different
One difference is that Qt Creator seems to use ninja to build, and on the command line you use make.
and I also don't know why I get the google issues within Qt Creator.
You include the generated .h file in main.cpp, but don't link your ProtobuffTutorial against your proto library, or protobuf.
Have you considered Qt Protobuf btw?
-
-
@kkoehne Thanks for your help. I realize that this isn't a Qt issue, but maybe you can (stll) help with the library issue.
My 2 cmake files now look like this
root
cmake_minimum_required(VERSION 3.14) project(ProtobuffTutorial LANGUAGES CXX) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Protobuf) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Protobuf) add_subdirectory(proto) add_executable(ProtobuffTutorial main.cpp ) target_include_directories(ProtobuffTutorial PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") target_link_libraries(ProtobuffTutorial Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Protobuf Proto ) include(GNUInstallDirs) install(TARGETS ProtobuffTutorial LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
proto
INCLUDE(FindProtobuf) FIND_PACKAGE(Protobuf REQUIRED) include_directories(${Protobuf_INCLUDE_DIR}) protobuf_generate_cpp(PROTO_SRC PROTO_HEADER message.proto) ADD_LIBRARY(Proto ${PROTO_HEADER} ${PROTO_SRC} ) target_link_libraries(Proto PUBLIC ProtoLib) target_sources (Proto PRIVATE message.proto ) include_directories(${CMAKE_CURRENT_BINARY_DIR}) target_include_directories(Proto PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
I followed the cmake docs from here
but it now loks for the ProtoLib library and I don't know where/how to define that
12:22:19: Running steps for project ProtobuffTutorial... 12:22:19: Starting: "/home/llist/Qt/Tools/CMake/bin/cmake" --build /home/llist/QtProjects/build-ProtobuffTutorial-Desktop_Qt_6_6_1_GCC_64bit-Debug --target all [1/8 237.8/sec] Running cpp protocol buffer compiler on message.proto [2/8 119.8/sec] Automatic MOC and UIC for target Proto [3/8 106.1/sec] Building CXX object proto/CMakeFiles/Proto.dir/Proto_autogen/mocs_compilation.cpp.o [4/8 5.4/sec] Building CXX object proto/CMakeFiles/Proto.dir/message.pb.cc.o [5/8 6.6/sec] Automatic MOC and UIC for target ProtobuffTutorial [6/8 7.8/sec] Building CXX object CMakeFiles/ProtobuffTutorial.dir/ProtobuffTutorial_autogen/mocs_compilation.cpp.o [7/8 3.8/sec] Building CXX object CMakeFiles/ProtobuffTutorial.dir/main.cpp.o [8/8 4.3/sec] Linking CXX executable ProtobuffTutorial FAILED: ProtobuffTutorial : && /usr/bin/x86_64-linux-gnu-g++ -DQT_QML_DEBUG -g proto/CMakeFiles/Proto.dir/Proto_autogen/mocs_compilation.cpp.o proto/CMakeFiles/Proto.dir/message.pb.cc.o CMakeFiles/ProtobuffTutorial.dir/ProtobuffTutorial_autogen/mocs_compilation.cpp.o CMakeFiles/ProtobuffTutorial.dir/main.cpp.o -o ProtobuffTutorial -Wl,-rpath,/home/llist/Qt/6.6.1/gcc_64/lib: /home/llist/Qt/6.6.1/gcc_64/lib/libQt6Protobuf.so.6.6.1 /home/llist/Qt/6.6.1/gcc_64/lib/libQt6Core.so.6.6.1 -lProtoLib && : /usr/bin/ld: cannot find -lProtoLib: No such file or directory collect2: error: ld returned 1 exit status ninja: build stopped: subcommand failed. 12:22:21: The process "/home/llist/Qt/Tools/CMake/bin/cmake" exited with code 1. Error while building/deploying project ProtobuffTutorial (kit: Desktop Qt 6.6.1 GCC 64bit) When executing step "Build" 12:22:21: Elapsed time: 00:02.
The object library is build-ProtobuffTutorial-Desktop_Qt_6_6_1_GCC_64bit-Debug/proto/libProto.a
I'm running cmake version 3.22.1Thanks
-
@Poldi I got it to link
root
cmake_minimum_required(VERSION 3.14) project(ProtobuffTutorial LANGUAGES CXX) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Protobuf) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Protobuf) add_subdirectory(proto) add_executable(ProtobuffTutorial main.cpp ) target_include_directories(ProtobuffTutorial PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") target_link_libraries(ProtobuffTutorial Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Protobuf ${Protobuf_LIBRARIES} Proto ) include(GNUInstallDirs) install(TARGETS ProtobuffTutorial LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
proto
INCLUDE(FindProtobuf) FIND_PACKAGE(Protobuf REQUIRED) include_directories(${Protobuf_INCLUDE_DIR}) protobuf_generate_cpp(PROTO_SRC PROTO_HEADER message.proto) ADD_LIBRARY(Proto ${PROTO_HEADER} ${PROTO_SRC} ) target_sources (Proto PRIVATE message.proto ) include_directories(${CMAKE_CURRENT_BINARY_DIR}) target_include_directories(Proto PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
-
-