VS 2019 CMake looking for file it is not supposed to - c++

I run into a problem when building a Cmake Project with CmakeLists.txt in VS 2019.
It tells me this:
What I did before the error:
I created a tests folder
I created a test.cpp file
A Pop up window opened from Cmake -> asking if I want to add it automatically to add_executable, I declined it
I manually added it to the Project Sources with tests/test.cpp
test got highlighted blue, so I changed the name to sample_test.cpp
rewrote test.cppp to sample_test.cpp
build CmakeLists.txt
error
I hope the provided information is enough otherwise let me know and thanks in advance!
What I tried:
deleting the cache
deleting the out file
deleting CMakeSettings.Json
repaired VS 2019
uninstalled CMake and reinstalled
Added the "ghost" file -> results in same error message
deleted repo and cloned it in a completely new directory
deleted .vs file
reinstalling VS 2019
deleting VS with InstallCleanup.exe, removed every VS file and reinstalled
Good to know:
On a colleagues machine it build without problems, so on his machine Cmake doesn't look for this file. So the problem seems to be locally on the machine.
Also I do not want this file and folder anymore, I have deleted it and somehow CMake is still looking for it.
cmake_minimum_required(VERSION 3.5)
project(team1 VERSION 0.1 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
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 Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
find_package(OpenCV REQUIRED)
find_package(PCL REQUIRED COMPONENTS common visualization io)
set(PROJECT_SOURCES
main.cpp
mainwindow.cpp mainwindow.h mainwindow.ui
userinterface.h userinterface.cpp
fileviewer.h fileviewer.cpp
segmentcreator.h segmentcreator.cpp
filerepresentation.h filerepresentation.cpp
filehandler.h filehandler.cpp
utils/utils.cpp utils/utils.h
)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(${PROJECT_NAME}
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
else()
if(ANDROID)
add_library(${PROJECT_NAME} SHARED
${PROJECT_SOURCES}
)
# Define properties for Android with Qt 5 after find_package() calls as:
else()
add_executable(${PROJECT_NAME}
${PROJECT_SOURCES}
)
endif()
endif()
target_link_libraries(${PROJECT_NAME}
PRIVATE Qt${QT_VERSION_MAJOR}::Widgets
${OpenCV_LIBS}
${PCL_LIBRARIES}
)
set_target_properties(${PROJECT_NAME} PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
install(TARGETS ${PROJECT_NAME}
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
target_include_directories(${PROJECT_NAME} PUBLIC
${OpenCV_INCLUDE_DIRS}
)
target_link_directories(${PROJECT_NAME} PUBLIC
${PCL_LIBRARY_DIRS}
${OpenCV_LIBRARY_DIRS}
)
add_definitions(${PCL_DEFINITIONS})
if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(${PROJECT_NAME})
endif()

I found a solution. I reinstalled Qt and it worked. I don't know if Qt somehow caches the files that are supposed to be used in a project, but reinstalling it at least made the CMake generate again without errors.
Maybe someone knows more about what Qt does there, I am curious to know.

Related

How can I make fat execuatable file in CMAKE?

I am newbie on CMAKE. I am trying to make "fat executable file".
The term, fat executeable file, I mentioned, is a executable binary file which contains all shared libraries and can be just run in another environment.
Example (Trouble Situation)
There is ComputerA which is a computer that I used for developing. There is GCC, Boost libraries, librados etc.
And there is ComputerB which is a computer that I wanted to execute the binary that I built.
* Of course, Both Computer A and B have some conditions. Same Intel CPU Arch. (i7), Same CentOS.
I built binary file in ComputerA using CMAKE with this command, cmake .. && make. And I copied this file to ComputerB and executed.
When I execute the copied binary file in Computer B, it said like below.
[root#ComputerB ~]# ./binaryFile 123.123.123.123
./binaryFile: error while loading shared libraries: libboost_json.so.1.80.0: cannot open shared object file: No such file or directory
I understand what this error message say. There is no shared library which it needed. So, what I want to ask in this community is, What is CMAKE Command for containing shared libraries.
Similar thing :: fat JAR
The reason, why I called "fat executable file", is that there is a word "fat JAR" in Java. I am not familiar with Java. But it is commonly used word in Java community.
My CMAKE File
It contains some libraries like Boost, Rados, RBD etc. (There will be more according to progress of developing)
cmake_minimum_required(VERSION 3.2.0)
project(BinaryHelper VERSION 0.1.0)
find_package(Boost REQUIRED COMPONENTS json)
include_directories(${Boost_INCLUDE_DIR})
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lrados -std=c++17")
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
add_executable(
${PROJECT_NAME}
main.cpp
utils/binary.cpp
utils/message.cpp
utils/header.cpp
)
target_link_libraries (
${PROJECT_NAME}
${Boost_LIBRARIES}
rados
rbd
Threads::Threads
)
Thanks to #HolyBlackCat, I solved the problem with static link.
Modified CMAKE
cmake_minimum_required(VERSION 3.2.0)
project(BinaryHelper VERSION 0.1.0)
find_package(Boost REQUIRED COMPONENTS json)
include_directories(${Boost_INCLUDE_DIR})
set(Boost_USE_STATIC_LIBS ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lrados -std=c++17")
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
add_library(
boost_json
STATIC
IMPORTED
)
set_target_properties(
boost_json
PROPERTIES
IMPORTED_LOCATION /usr/local/lib/libboost_json.a
)
add_executable(
${PROJECT_NAME}
main.cpp
utils/binary.cpp
utils/message.cpp
utils/header.cpp
)
# target_link_libraries (
# ${PROJECT_NAME}
# ${Boost_LIBRARIES}
# rados
# rbd
# Threads::Threads
# )
target_link_libraries(
${PROJECT_NAME}
boost_json
rados
rbd
Threads::Threads
)
There is additional(modified) keywords, add_library, set_target_properties, target_link_libraries.

Cannot build cmake project with including directories in cmake project

|---Engine
|----CMakeList.txt
|----Engine.cpp
|----Engine.h
|---Models
|----CMakeList.txt
|----Snake.cpp
|----Snake.hpp
|---Type
|----CMakeList.txt
|----Point.hpp
|---CMakeList.txt
|---main.cpp
I just can't tell the main sheet that I want to add a directory with files to it ...
Each time, errors of the following type appear:
CMake Error at CMakeLists.txt: 12 (target_include_directories):
Cannot specify include directories for target "Snake" which is not built by
this project.
CMake Error at CMakeLists.txt: 13 (target_link_directories):
Cannot specify link directories for target "Snake" which is not built by
this project.
CMake Error at Engine / CMakeLists.txt: 8 (target_include_directories):
Cannot specify include directories for target "Snake" which is not built by
this project.
CMake Error at CMakeLists.txt: 17 (target_link_libraries):
Cannot specify link libraries for target "Snake" which is not built by this
project.
- Configuring incomplete, errors occurred!
Which, for several hours of intensified attempts, are not corrected in any way. Can anyone help with this?
CMakeLists.txt from Engine folder:
set(HEADERS
Engine.h)
set(SOURCES
Engine.cpp)
add_library(Engine ${HEADERS} ${SOURCES})
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR})
Main CMakeList.txt:
cmake_minimum_required(VERSION 3.16.3)
project(Snake)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(PROJECT_SOURCES
main.cpp
)
target_include_directories(${PROJECT_NAME} PUBLIC Engine)
target_link_directories(${PROJECT_NAME} PUBLIC Engine)
add_subdirectory(Engine)
target_link_libraries(${PROJECT_NAME} Engine)
add_executable(${PROJECT_NAME}
${PROJECT_SOURCES}
)
find_package(SFML 2.5.1 COMPONENTS graphics audio REQUIRED)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} sfml-graphics sfml-audio)
set(SFML_STATIC_LIBRARIES FALSE)
There are two errors. The first one is to call a PROJECT_NAME that hasn't been built yet. add_executable(${PROJECT_NAME} ...) and add_library(${PROJECT_NAME ...) should be used before the target_include_directories and target_link_directories that refers to it. Because, as #Stephen Newell noted, otherwise you will be using a PROJECT NAME that hasn't been declared/built yet.
The second error is that you are calling a PROJECT_NAME inside Engine/CMakeLists. Maybe you are missing a project(...) inside of it.
Maybe you should move set(SFML_STATIC_LIBRARIES FALSE) before linking it, as well.

Encounter issue with `find_package` command in Visual Studio CMake

I'm operating under a new learning curve here with c++ and using CMake in Visual Studio. Here is the partial code up until the point where I receive the error:
project(libfranka
VERSION 0.8.0
LANGUAGES CXX
)
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/cmake)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(MSVC)
add_compile_options(/W0)
else()
add_compile_options(-Wall -Wextra)
endif()
set(THIRDPARTY_SOURCES_DIR "${CMAKE_SOURCE_DIR}/3rdparty" CACHE PATH
"Directory for third-party sources")
## Dependencies
find_package(Poco REQUIRED COMPONENTS Net Foundation)
find_package(Eigen3 REQUIRED)
Once it hits the first find_package is where I encounter the error:
Here is the code within FindPoco.cmake.
find_package(Poco COMPONENTS ${Poco_FIND_COMPONENTS} CONFIG QUIET)
if(Poco_FOUND)
return()
endif()
find_path(Poco_INCLUDE_DIR Poco/Poco.h)
mark_as_advanced(FORCE Poco_INCLUDE_DIR)
foreach(component ${Poco_FIND_COMPONENTS})
set(component_var "Poco_${component}_LIBRARY")
find_library(${component_var} Poco${component})
mark_as_advanced(FORCE ${component_var})
if(${component_var})
set(Poco_${component}_FOUND TRUE)
list(APPEND Poco_LIBRARIES ${component})
if(NOT TARGET Poco::${component})
add_library(Poco::${component} SHARED IMPORTED)
set_target_properties(Poco::${component} PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${Poco_INCLUDE_DIR}
IMPORTED_LOCATION ${${component_var}}
)
endif()
endif()
endforeach()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Poco
FOUND_VAR Poco_FOUND
REQUIRED_VARS Poco_INCLUDE_DIR Poco_LIBRARIES
VERSION_VAR Poco_VERSION
HANDLE_COMPONENTS
)
I installed poco using vcpkg in a directory titled vcpkg. Within the vcpkg directory is the libfranka directory, which houses the CMakeLists.txt file that I compile in Visual Studio. Here is an image of that directory:
Finally, here is the tutorial that I am using: https://frankaemika.github.io/docs/installation_windows.html#building-from-source
EDIT:
Per the link I followed the instructions for solving the build dependencies and here is an image of that:
Then I ran the CMakeLists.txt again and in the CMake Settings this is what I see:
Note also that I ran through the install of poco again and I noticed this and am unsure if it could be the source of the problem or if it means nothing (again, this was the out put after running vcpkg install poco):
After this I still receive the same error.
Does anyone see what it is that I am doing incorrectly?
Thank you!

What does this strange "/usr/bin/ld: cannot find -lXAW_LIBRARY-NOTFOUND" error mean?

I created a ROS2 rviz plugin in C++ which I need to compile into a shared library (.so) using cmake. I already have a working CMakeLists.txt (see below) which creates a static library (.a); I need it to be shared, though.
However, when I add the SHARED keyword to the add_library macro (commented out in the code below), it throws this strange error:
/usr/bin/ld: cannot find -lXAW_LIBRARY-NOTFOUND
Now, I have looked at the many "/usr/bin/ld: cannot find [some library]" questions here on SO (like this), but my error seems to be more strange since it seems to contain an error ("-lXAW_LIBRARY-NOTFOUND") IN THE error (/usr/bin/ld: cannot find...). I mean, why is he even looking for a library called LIBRARY_NOTFOUND??
I'm on Ubuntu xenial 16.04 using cmake 3.10.
CMakeLists.txt:
project(traffic_sign_delegation_manager)
set(CMAKE_CXX_STANDARD 17)
if(NOT WIN32)
add_definitions(-fPIC)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic -Wno-deprecated-declarations)
endif()
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rviz_common REQUIRED)
find_package(std_msgs REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(rosidl_generator_cpp)
find_package(pluginlib REQUIRED)
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5OpenGL REQUIRED)
find_package(Qt5 REQUIRED COMPONENTS Widgets)
set(msg_files
"msg/TrafficSignList.msg"
"msg/TrafficSign.msg"
"msg/TrafficSignSetList.msg"
"msg/TrafficSignSet.msg"
"msg/TrafficSignSetStatus.msg"
"msg/TrafficSignsManaged.msg"
"msg/AccLever2.msg"
"msg/VehicleOdometry.msg"
)
rosidl_generate_interfaces(${PROJECT_NAME}
${msg_files}
DEPENDENCIES std_msgs
)
link_directories(${ament_cmake_LIBRARY_DIRS})
add_definitions(-DQT_NO_KEYWORDS)
qt5_wrap_ui(QT_UI_FILES ui/traffic_sign_delegation_manager_panel.ui)
qt5_wrap_ui(QT_UI_FILES ui/traffic_sign_list_item.ui)
qt5_add_resources(QT_QRC_FILES ui/traffic_sign_delegation_manager.qrc)
set_property(SOURCE traffic_sign_delegation_manager_panel.h PROPERTY SKIP_AUTOMOC ON)
set_property(SOURCE draw_area.h PROPERTY SKIP_AUTOMOC ON)
set_property(SOURCE adv_interaction_groupbox.h PROPERTY SKIP_AUTOMOC ON)
set_property(SOURCE traffic_sign_delegation_manager_display.h PROPERTY SKIP_AUTOMOC ON)
add_library(delegator_lib # SHARED # <=== WHY IS THIS NOT WORKING?
vec2d.cpp
vec2d.h
traffic_sign_delegation_manager_panel.cpp
traffic_sign_delegation_manager_panel.h
draw_area.cpp
draw_area.h
traffic_sign_delegation_manager_display.cpp
traffic_sign_delegation_manager_display.h
adv_interaction_groupbox.cpp
adv_interaction_groupbox.h
ui/traffic_sign_list_item.ui
ui/traffic_sign_delegation_manager_panel.ui
${QT_UI_FILES}
${MOC_FILES}
)
rosidl_target_interfaces(delegator_lib ${PROJECT_NAME} "rosidl_typesupport_cpp")
target_include_directories(delegator_lib PUBLIC
${rvizCommon_DIR}
${rosidl_generator_cpp_INCLUDE_DIRS}
${ament_cmake_INCLUDE_DIRS}
${rviz2_INCLUDE_DIRS}
${rviz_common_INCLUDE_DIRS}
${FREETYPE_INCLUDE_DIRS}
${Qt5_INCLUDE_DIRS}
)
target_link_libraries(delegator_lib
rviz_common::rviz_common
)
target_compile_definitions(delegator_lib PRIVATE "RVIZ_DEFAULT_PLUGINS_BUILDING_LIBRARY")
target_compile_definitions(delegator_lib PUBLIC "PLUGINLIB__DISABLE_BOOST_FUNCTIONS")
pluginlib_export_plugin_description_file(rviz_common plugin_description.xml)
ament_target_dependencies(delegator_lib
geometry_msgs
laser_geometry
nav_msgs
map_msgs
rclcpp
resource_retriever
urdf
visualization_msgs
)
ament_export_include_directories(${INCLUDE_DIRS} ${ament_cmake_INCLUDE_DIRS} include)
ament_export_interfaces(delegator_lib HAS_LIBRARY_TARGET)
ament_export_dependencies(
Qt5
rviz_common
geometry_msgs
laser_geometry
map_msgs
nav_msgs
rclcpp
urdf
visualization_msgs
rosidl_generator_cpp
)
install(FILES plugin_description.xml
DESTINATION share/${PROJECT_NAME})
install(DIRECTORY images
DESTINATION share/${PROJECT_NAME})
install(DIRECTORY ui
DESTINATION share/${PROJECT_NAME}
PATTERN "*.ui"
EXCLUDE)
install(
TARGETS delegator_lib
EXPORT delegator_lib
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)
install(
DIRECTORY "${CMAKE_SOURCE_DIR}/icons"
DESTINATION "share/${PROJECT_NAME}"
)
ament_package()
Please note: This question is not about ROS; I am not a cmake wizard, so probably I'm just doing something terribly wrong in cmake... I already asked a more broad version of this question on answers.ros, but it appears to be too cmake-specific or something. Anyway, I did not get an answer there. (The above code is not an MWE, sorry; I could create one if neccessary, but it would require ROS2 to compile...)
Normally that error pops up if you are giving some library names as arguments to the target_link_libraries function.
Either,
The names are not correct or,
The path is not or,
The libraries are not installed.
I'd look at target_link_libraries(delegator_lib rviz_common::rviz_common) and link_directories(${ament_cmake_LIBRARY_DIRS}) as suspects.
In CMake you can use MESSAGE command to do debugging of sorts where you can display the values of the CMake variables to check if they make sense with what is on the system.
Also you can try installing the XAW library like this sudo apt-get install libxaw7-dev. Could be that one of the libraries that you link to has a dependency on the XAW library.

CMake Automoc Error 1 - Can't compile project

I just moved a project I built in Qt5 into my CMake project tree.
I exported the project in the CMake directory. However as I try to build the project the compiler gives me the following error:
[src/GUIconceptStudy/CMakeFiles/GUIconceptStudy_automoc] Error 1
See also the following print screen attached:
Also the CMakeLists.txt files is below:
cmake_minimum_required (VERSION 3.1)
project(GUIconceptStudy)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
find_package( OpenCV REQUIRED )
find_package( Boost COMPONENTS system thread filesystem REQUIRED)
#find_package (sqlite3)
find_package(Qt5 REQUIRED COMPONENTS Core Quick)
###
### make sure we use c++11
###
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
###
###boost include stuff (required for all libcam)
###
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )
find_package(Qt5Widgets)
find_package(Qt5PrintSupport)
#find all the qt UI stuff
file(GLOB UI
"ui/*.ui"
)
#make them into headers
qt5_wrap_ui (UI_HDRS ${UI})
###
### add all your non QT sources
###
# find all non ui sources
file(GLOB SRCS
"src/*.h"
"src/*.cpp"
"src/*.hpp"
)
# find all ui related sources
file(GLOB UI_SRCS
"ui/*.h"
"ui/*.cpp"
"ui/*.hpp"
)
###
### Add executables
###
add_executable(GUIconceptStudy main/main.cpp ui/qrc/res.qrc ${SRCS} ${UI_HDRS} ${UI_SRCS})
target_link_libraries (GUIconceptStudy Qt5::Widgets ${Boost_LIBRARIES} ${OpenCV_LIBS} Qt5::PrintSupport Qt5::Core Qt5::Quick)
###
### Add Library
###
add_library(GUIconceptStudy_lib SHARED ui/qrc/res.qrc ${SRCS} ${UI_HDRS} ${UI_SRCS})
target_link_libraries (GUIconceptStudy_lib Qt5::Widgets ${Boost_LIBRARIES} ${OpenCV_LIBS} Qt5::PrintSupport Qt5::Core Qt5::Quick)
After looking at different on-line sources I could't find anything particularly useful. Anyone who can shed a little bit of light on what the problem could be?
It's a shot in a dark but this is most likely caused by the missing set(CMAKE_INCLUDE_CURRENT_DIR ON). As said in the documentation it should set because generated files are not in your source directory:
Generated moc_*.cpp and *.moc files are placed in the build directory so it is convenient to set the CMAKE_INCLUDE_CURRENT_DIR variable.
Another mistake I see people doing is mixing Qt processing pipelines. I've mentioned this already in my other answers. As it says in documentation on AUTOUIC property you shouldn't use qt5_wrap_ui function when this property is enabled.