CMake Linker failing building executable with static functions - c++

I'll try to describe this issue the best I can. I'm trying to catkin_make a multi-package c++ project, but I'm getting a couple linker issues when its trying to build executables for 2 of the packages.
The error:
forge/devel/lib/libforge_features.so: undefined reference to `ErrorClientKeeper::addError(ForgeError::Severity, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool)'
collect2: error: ld returned 1 exit status
forge_feature_identification/CMakeFiles/feature_identification_service_node.dir/build.make:224: recipe for target '/home/brian-pc/forge/devel/lib/forge_feature_identification/feature_identification_service_node' failed
make[2]: *** [/home/brian-pc/forge/devel/lib/forge_feature_identification/feature_identification_service_node] Error 1
CMakeFiles/Makefile2:8322: recipe for target 'forge_feature_identification/CMakeFiles/feature_identification_service_node.dir/all' failed
make[1]: *** [forge_feature_identification/CMakeFiles/feature_identification_service_node.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
CMakeFiles/part_manager_node.dir/src/part.cpp.o: In function `Part::read(int)':
part.cpp:(.text+0x88f): undefined reference to `ErrorClientKeeper::addError(ForgeError::Severity, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool)'
part.cpp:(.text+0x102b): undefined reference to `ErrorClientKeeper::addError(ForgeError::Severity, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool)'
CMakeFiles/part_manager_node.dir/src/part.cpp.o: In function `Part::createFromTemplate(int)':
part.cpp:(.text+0x137d): undefined reference to `ErrorClientKeeper::addError(ForgeError::Severity, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool)'
part.cpp:(.text+0x1a21): undefined reference to `ErrorClientKeeper::addError(ForgeError::Severity, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool)'
collect2: error: ld returned 1 exit status
forge_part_manager/CMakeFiles/part_manager_node.dir/build.make:172: recipe for target '/home/brian-pc/forge/devel/lib/forge_part_manager/part_manager_node' failed
make[2]: *** [/home/brian-pc/forge/devel/lib/forge_part_manager/part_manager_node] Error 1
CMakeFiles/Makefile2:9105: recipe for target 'forge_part_manager/CMakeFiles/part_manager_node.dir/all' failed
make[1]: *** [forge_part_manager/CMakeFiles/part_manager_node.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
feature_identification_service_node and part_manager_node are the exes its trying to build.
The function its trying to reference is a static function is a package called forge_errors declared in file error_client_keeper.h. Here is the header file for that:
#ifndef __ERROR_CLIENT_KEEPER_H_INCLUDED__
#define __ERROR_CLIENT_KEEPER_H_INCLUDED__
#include <ros/ros.h>
#include <forge_errors/Error.h>
#include <forge_errors/forge_error.h>
#include <forge_errors/alert_service.h>
#include <forge_errors/error_client.h>
class ErrorClientKeeper
{
public:
static bool addError(ForgeError err);
static bool addError(ForgeError::Severity severity, std::string msg, std::string caller = "", bool display = true);
private:
ErrorClientKeeper();
~ErrorClientKeeper(){};
};
#endif
The .cpp file:
#include <forge_errors/error_client_keeper.h>
bool addError(ForgeError err)
{
ros::NodeHandle nh;
ErrorClient client(nh);
bool success = client.addError(err);
ros::spinOnce();
return success;
}
bool addError(ForgeError::Severity severity, std::string msg, std::string caller = "", bool display = true)
{
ros::NodeHandle nh;
ErrorClient client(nh);
bool success = client.addError(severity, msg, caller, display);
ros::spinOnce();
return success;
}
forge error is a class also in the forge_errors package, in forge_error.h
Here's the feature_identification package's cmakelists.txt
cmake_minimum_required(VERSION 2.8.3)
project(forge_feature_identification)
find_package(catkin REQUIRED COMPONENTS
forge_msgs
forge_features
roscpp
rospy
actionlib
actionlib_msgs
)
###################################
## catkin specific configuration ##
###################################
catkin_package(
CATKIN_DEPENDS
forge_msgs
forge_features
roscpp
rospy
actionlib
actionlib_msgs
)
###########
## Build ##
###########
include_directories(
include
${catkin_INCLUDE_DIRS}
)
add_executable(
feature_identification_service_node
src/feature_identification_service_node.cpp
src/feature_identification_service.cpp
src/feature_identifier.cpp
src/seam_identifier.cpp
src/part_model_identifier.cpp
)
target_link_libraries(
feature_identification_service_node
${catkin_LIBRARIES}
)
add_dependencies(
feature_identification_service_node
${catkin_EXPORTED_TARGETS}
)
#############
## Install ##
#############
# Mark cpp header files for installation
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h"
PATTERN ".svn" EXCLUDE
)
Here's part_manager_node's cmakelist.txt
project(forge_part_manager)
## Find catkin macros and libraries
find_package(catkin REQUIRED COMPONENTS
forge_db_manager
forge_utils
forge_msgs
forge_features
forge_feature_identification
actionlib
roscpp
forge_errors
rospy
std_msgs
)
###################################
## catkin specific configuration ##
###################################
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES forge_part_manager
CATKIN_DEPENDS
forge_db_manager
forge_utils
forge_features
forge_feature_identification
roscpp
rospy
std_msgs
forge_errors
actionlib
# DEPENDS system_lib
)
###########
## Build ##
###########
include_directories(
include
${catkin_INCLUDE_DIRS}
)
add_executable(
part_manager_node
src/part_manager_node.cpp
src/part_manager.cpp
src/part.cpp
)
target_link_libraries(
part_manager_node
${catkin_LIBRARIES}
)
#############
## Install ##
#############
There's more relevant files I can show, but this is already getting pretty long. The forge_features package depends on forge_errors, and the files in it all
#include <forge_errors/error_client_keeper.h>
#include <forge_errors/forge_error.h>
in the header files. And in the cmakelists for forge_features they're listed under find_package and catkin_package( CATKIN_DEPENDS, as well as in the package.xml for build and exec dependencies
part.h also includes those two files.
here's the relevant section of the errors package cmakelists:
catkin_package(
INCLUDE_DIRS
include
LIBRARIES
forge_errors
CATKIN_DEPENDS
forge_msgs
forge_db_manager
forge_utils
roscpp
)
###########
## Build ##
###########
include_directories(
include
${catkin_INCLUDE_DIRS}
)
add_library(
forge_errors
src/forge_error.cpp
src/error_service.cpp
src/error_service_node.cpp
src/error_client.cpp
src/alert_service.cpp
src/error_client_keeper.cpp
)
target_link_libraries(
forge_errors
${catkin_LIBRARIES}
)
add_dependencies(
forge_errors
${PROJECT_NAME}_generate_messages_cpp
${catkin_EXPORTED_TARGETS}
)
add_executable(
error_service_node
src/error_service_node.cpp
src/error_service.cpp
src/forge_error.cpp
src/alert_service.cpp
)
target_link_libraries(
error_service_node
${catkin_LIBRARIES}
)
add_dependencies(
error_service_node
${PROJECT_NAME}_generate_messages_cpp
${catkin_EXPORTED_TARGETS}
)
#############
## Install ##
#############
# Mark cpp header files for installation
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h"
PATTERN ".svn" EXCLUDE
)
I can provide any other files it would help to see, but this post is too long already, so hopefully someone is able to wade through it and knows what the issue is, because I don't. forge_errors should be a complete and correctly building library, and I don't know why it can't link it to these executables.

Related

Undefined reference to boost in catkin_make

I'am working on melodic and trying to add SDK to ROS in my ubuntu 18.04. When I was do catkin_make in command line, I got an error be like :
'/home/jenana/catkin_ws/src/Sonar/libs/GeminiComms/x86_64-linux-gnu/x64/Release/libGeminiComms.so: undefined reference to boost::re_detail_106501::cpp_regex_traits_implementation<wchar_t>::transform_primary(wchar_t const*, wchar_t const*) const' /home/jenana/catkin_ws/src/Sonar/libs/GeminiComms/x86_64-linux-gnu/x64/Release/libGeminiComms.so: undefined reference to boost::re_detail_106501::cpp_regex_traits_implementation::transform(char const*, char const*) const' /home/jenana/catkin_ws/src/Sonar/libs/GeminiComms/x86_64-linux-gnu/x64/Release/libGeminiComms.so: undefined reference to boost::re_detail_106501::cpp_regex_traits_implementation<wchar_t>::transform(wchar_t const*, wchar_t const*) const' /home/jenana/catkin_ws/src/Sonar/libs/GeminiComms/x86_64-linux-gnu/x64/Release/libGeminiComms.so: undefined reference to boost::re_detail_106501::cpp_regex_traits_implementation::transform_primary(char const*, char const*) const' collect2: error: ld returned 1 exit status Sonar/src/geminisdkconsoleapp/CMakeFiles/geminisdkconsoleapp1.dir/build.make:116: recipe for target '/home/jenana/catkin_ws/devel/lib/geminisdk/geminisdkconsoleapp1' failed make[2]: [/home/jenana/catkin_ws/devel/lib/geminisdk/geminisdkconsoleapp1] Error 1 CMakeFiles/Makefile2:1037: recipe for target 'Sonar/src/geminisdkconsoleapp/CMakeFiles/geminisdkconsoleapp1.dir/all' failed make[1]: [Sonar/src/geminisdkconsoleapp/CMakeFiles/geminisdkconsoleapp1.dir/all] Error 2 Makefile:140: recipe for target 'all' failed make: *** [all] Error 2'.
Does anyone know how to solve it ?
I've already put the boost in TARGET_LINK_LIBRARIES, but I got still an error.
I also attached my package Cmakelist file, package.xml, and my sub package Cmakelist file below:
My package Cmakelist file :
cmake_minimum_required(VERSION 3.5.1)
PROJECT(geminisdk)
if (POLICY CMP0071)
cmake_policy(SET CMP0071 OLD)
endif()
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set (ARCH ARCH64)
message ( "Arch : ${ARCH}" )
set(SDK_PLATFORM_NAME x32)
find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs genmsg message_generation)
find_package(Boost REQUIRED COMPONENTS system thread filesystem)
catkin_package(
CATKIN_DEPENDS roscpp std_msgs message_runtime
DEPENDS Boost
)
INCLUDE_DIRECTORIES(
include
${Boost_INCLUDE_DIRS}
${catkin_INCLUDE_DIRS}
)
if("${ARCH}" STREQUAL "ARCH32")
set(SDK_PLATFORM_NAME x32)
elseif("${ARCH}" STREQUAL "AARCH64")
#arm arch64
set(SDK_PLATFORM_NAME aarch64)
else()
set(SDK_PLATFORM_NAME x64)
endif()
if( "${CMAKE_BUILD_TYPE}" STREQUAL "" )
set(CMAKE_BUILD_TYPE Release)
endif()
if( "${_LOW_PERFORMANCE_CPU_}" STREQUAL "1" )
add_definitions(-D_LOW_PERFORMANCE_CPU_)
endif()
if( "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" )
set(STATIC_LIB_PREFIX "")
set(DYNAMIC_LIB_SUFFIX lib)
if( ${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC )
add_definitions(-D_WIN32_WINNT=0x0601 -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS)
endif()
Set( LIB_ARCHITECTURE ${CMAKE_SYSTEM_NAME})
else()
set(STATIC_LIB_PREFIX lib)
set(DYNAMIC_LIB_SUFFIX so)
if( "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7at2hf-neon-angstrom" )
Set (CMAKE_CXX_LIBRARY_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR} )
endif()
if( "${CMAKE_CXX_LIBRARY_ARCHITECTURE}" STREQUAL "" )
set(CMAKE_CXX_LIBRARY_ARCHITECTURE ${CMAKE_SYSTEM_NAME})
endif()
Set( LIB_ARCHITECTURE ${CMAKE_CXX_LIBRARY_ARCHITECTURE})
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
#set( SYSTEM_LIBRARIES "-lrt -lpthread")
# Enable static linking for gcc and stdc++
set(CMAKE_SHARED_LINKER_FLAGS "-static-libstdc++ -static-libgcc ${CMAKE_SHARED_LINKER_FLAGS}")
set( zLIBWARPPER_LIB ${CMAKE_CURRENT_SOURCE_DIR}/libs/zLibWrapper/${LIB_ARCHITECTURE}/${SDK_PLATFORM_NAME}/${CMAKE_BUILD_TYPE}/${STATIC_LIB_PREFIX}zLibWrapper.${DYNAMIC_LIB_SUFFIX} )
endif()
set( GEMINI_COMMS_LIB ${CMAKE_CURRENT_SOURCE_DIR}/libs/GeminiComms/${LIB_ARCHITECTURE}/${SDK_PLATFORM_NAME}/${CMAKE_BUILD_TYPE}/${STATIC_LIB_PREFIX}GeminiComms.${DYNAMIC_LIB_SUFFIX} )
set( SVS5_LIB ${CMAKE_CURRENT_SOURCE_DIR}/libs/Svs5SeqLib/${LIB_ARCHITECTURE}/${SDK_PLATFORM_NAME}/${CMAKE_BUILD_TYPE}/${STATIC_LIB_PREFIX}Svs5SeqLib.${DYNAMIC_LIB_SUFFIX} )
set( GNS_SERIALIZER_LIB ${CMAKE_CURRENT_SOURCE_DIR}/libs/GenesisSerializer/${LIB_ARCHITECTURE}/${SDK_PLATFORM_NAME}/${CMAKE_BUILD_TYPE}/${STATIC_LIB_PREFIX}GenesisSerializer.${DYNAMIC_LIB_SUFFIX} )
add_subdirectory (src/geminisdkconsoleapp)
Set( EXPORT_EXE_FILES
${CMAKE_CURRENT_BINARY_DIR}/src/geminisdkconsoleapp/geminisdkconsoleapp1
)
This is my package.xml file:
<?xml version="1.0"?>
<package format="2">
<name>geminisdk</name>
<version>0.0.0</version>
<description>The geminisdk package</description>
<maintainer email="jungde#todo.todo">jungde</maintainer>
<license>TODO</license>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>roscpp</build_depend>
<build_depend>rospy</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>Boost</build_depend>
<build_depend>message_generation</build_depend>
<exec_depend>message_runtime</exec_depend>
<build_export_depend>roscpp</build_export_depend>
<build_export_depend>rospy</build_export_depend>
<build_export_depend>std_msgs</build_export_depend>
<exec_depend>roscpp</exec_depend>
<exec_depend>rospy</exec_depend>
<exec_depend>std_msgs</exec_depend>
<export>
</export>
</package>
This is my sub package Cmakelist file :
PROJECT(geminisdkconsoleapp)
add_executable(geminisdkconsoleapp1 GeminiSDKConsole1.cpp)
TARGET_LINK_LIBRARIES(geminisdkconsoleapp1
${GNS_SERIALIZER_LIB}
${zLIBWARPPER_LIB}
${SVS5_LIB}
${GEMINI_COMMS_LIB}
${SYSTEM_LIBRARIES}
${catkin_LIBRARIES}
${Boost_LIBRARY}
)

How to link to the code that defines the sdl_image.h functions?

I'm trying to add sound and music to my openGL project. I'm using Cmake. I get undefined reference errors and have tried for days using many methods and suggestions I've read about, but I am over my head apparently.
I have installed the libraries that I think are needed, I have configured and make installed, tried, finding the packages, added module code to help facilitate it. I am somewhat aware not all of these methods are likely useful in my case. Or maybe I need to have these libraries in my project folder and on my system ...installed. Ok, not super clear about that. I am using Ubuntu Linux with codeblocks to edit my scripts, but not to compile.
My cmakelists.text
cmake_minimum_required (VERSION 3.0)
project (maficengine LANGUAGES C CXX ASM)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/external/")
find_package(OpenGL REQUIRED)
#FIND_PACKAGE(SDL2_MIXER)
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS} ${SDL2_IMAGE_INCLUDE_DIRS})
#target_link_libraries(maficengine ${SDL2_LIBRARIES} ${SDL2_IMAGE_LIBRARIES})
find_file(SDL2_INCLUDE_DIR NAME SDL.h HINTS SDL2)
find_library(SDL2_LIBRARY NAME SDL2)
set(SDL2_INCLUDE_DIR /usr/include/SDL2)
set(SDL2_LIBRARY /usr/lib/x86_64-linux-gnu/libSDL2.so)
#file(GLOB_RECURSE SOURCE_FILES/usr/lib/x86_64-linux-gnu
# ${CMAKE_SOURCE_DIR}/src/*.c
# ${CMAKE_SOURCE_DIR}/src/*.cpp)
INCLUDE(FindPkgConfig)
PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2)
PKG_SEARCH_MODULE(SDL REQUIRED sdl)
set(SDL_INCLUDE_DIR "/usr/include/SDL2")
set(SDL_LIBRARY "SDL2")
include(FindSDL)
if(SDL_FOUND)
message(STATUS "SDL FOUND")
elseif(!SDL_FOUND)
message(STATUS "SDL not FOUND")
endif()
find_library(SDL_MIXER_LIBRARY
NAMES SDL2_mixer
HINTS
ENV SDLMIXERDIR
ENV SDLDIR
PATH_SUFFIXES lib
)
if( CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR )
message( FATAL_ERROR "Please select another Build Directory ! (and give it a clever name, like bin_Visual2012_64bits/)" )
endif()
if( CMAKE_SOURCE_DIR MATCHES " " )
message( "Your Source Directory contains spaces. If you experience problems when compiling, this can be the cause." )
endif()
if( CMAKE_BINARY_DIR MATCHES " " )
message( "Your Build Directory contains spaces. If you experience problems when compiling, this can be the cause." )
endif()
file(GLOB SOURCES "external/myCustomHeaders/*.cpp")
add_library(loaders SHARED ${SOURCES}
${SDL2_INCLUDE_DIR}
external/SDL2_image-2.0.4/SDL_image.h
external/myCustomHeaders/include/loadTexture.h
external/myCustomHeaders/loadTexture.cpp
/usr/include/SDL2/SDL.h
/usr/include/SDL/SDL_image.h
external/SDL2_mixer-2.0.4/SDL_mixer.h
)
include_directories( external/myCustomHeaders/include )
include_directories( external/SDL2_mixer-2.0.4/acinclude )
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}external/SDL2_mixer-2.0.4 )
include_directories(/usr/include/SDL2)
include_directories(/usr/include/SDL)
include_directories(${SDL2_INCLUDE_DIRS})
include(FindPackageHandleStandardArgs)
find_path(
SDL_MIXER_INCLUDE_DIR
PATHS
/usr/include/SDL
/usr/include/SDL2
/usr/include
/usr/local/include
/sw/include
/opt/local/include
${SDL_MIXER_ROOT_DIR}/include
DOC "The directory where SDL_mixer.h resides")
link_directories(external/myCustomHeaders/include)
link_directories(external/myCustomHeaders)
link_directories(external/SDL2_mixer-2.0.4)
link_directories(/usr/include/SDL2)
link_directories(/usr/include/SDL)
# Compile external dependencies
add_subdirectory (external)
# On Visual 2005 and above, this module can set the debug working directory
cmake_policy(SET CMP0026 OLD)
cmake_policy(SET CMP0079 NEW)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/external/rpavlik-cmake-modules-fe2273")
include(CreateLaunchers)
include(MSVCMultipleProcessCompile) # /MP
if(INCLUDE_DISTRIB)
add_subdirectory(distrib)
endif(INCLUDE_DISTRIB)
include_directories(
external/AntTweakBar-1.16/include/
external/glfw-3.1.2/include/
external/glm-0.9.7.1/
external/glew-1.13.0/include/
external/assimp-3.0.1270/include/
external/bullet-2.81-rev2613/src/
external/myCustomHeaders/include
common/
)
set(ALL_LIBS
${OPENGL_LIBRARY}
glfw
GLEW_1130
loaders
)
add_definitions(
-DTW_STATIC
-DTW_NO_LIB_PRAGMA
-DTW_NO_DIRECT3D
-DGLEW_STATIC
-D_CRT_SECURE_NO_WARNINGS
)
# Tutorial 17
add_executable(mageengine
${SDL2_LIBRARY}
Mafic/mafic.cpp
common/shader.cpp
common/shader.hpp
common/controls.cpp
common/controls.hpp
common/texture.cpp
common/texture.hpp
common/objloader.cpp
common/objloader.hpp
common/vboindexer.cpp
common/vboindexer.hpp
common/quaternion_utils.cpp
common/quaternion_utils.hpp
Mafic/StandardShading.vertexshader
Mafic/StandardShading.fragmentshader
)
set_target_properties(loaders
PROPERTIES LINKER_LANGUAGE CXX)
#target_sources(loaders
# PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/myCustomHeaders/loadTexture.h
# )
target_link_libraries(mageengine
${ALL_LIBS}
ANTTWEAKBAR_116_OGLCORE_GLFW
${SDL2_LIBRARIES}
loaders
)
#target_link_libraries(${maficengine } SDL2::Main SDL2::Image)
# Xcode and Visual working directories
set_target_properties(mageengine PROPERTIES XCODE_ATTRIBUTE_CONFIGURATION_BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Mafic/")
create_target_launcher(mageengine WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/Mafic/")
SOURCE_GROUP(common REGULAR_EXPRESSION ".*/common/.*" )
SOURCE_GROUP(shaders REGULAR_EXPRESSION ".*/.*shader$" )
if (NOT ${CMAKE_GENERATOR} MATCHES "Xcode" )
add_custom_command(
TARGET mageengine POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/mageengine${CMAKE_EXECUTABLE_SUFFIX}" "${CMAKE_CURRENT_SOURCE_DIR}/Mafic/"
)
#target_link_libraries(mageengine LINK_PUBLIC ${mylibrary}
# )
elseif (${CMAKE_GENERATOR} MATCHES "Xcode" )
endif (NOT ${CMAKE_GENERATOR} MATCHES "Xcode" )
this is my module code that I'm using, I assume its possibly being used by cmake
# Locate SDL_image library
#
# This module defines:
#
# ::
#
# SDL2_IMAGE_LIBRARIES, the name of the library to link against
# SDL2_IMAGE_INCLUDE_DIRS, where to find the headers
# SDL2_IMAGE_FOUND, if false, do not try to link against
# SDL2_IMAGE_VERSION_STRING - human-readable string containing the version of SDL_image
#
#
#
# For backward compatibility the following variables are also set:
#
# ::
#
# SDLIMAGE_LIBRARY (same value as SDL2_IMAGE_LIBRARIES)
# SDLIMAGE_INCLUDE_DIR (same value as SDL2_IMAGE_INCLUDE_DIRS)
# SDLIMAGE_FOUND (same value as SDL2_IMAGE_FOUND)
#
#
#
# $SDLDIR is an environment variable that would correspond to the
# ./configure --prefix=$SDLDIR used in building SDL.
#
# Created by Eric Wing. This was influenced by the FindSDL.cmake
# module, but with modifications to recognize OS X frameworks and
# additional Unix paths (FreeBSD, etc).
#=============================================================================
# Copyright 2005-2009 Kitware, Inc.
# Copyright 2012 Benjamin Eikel
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
find_path(SDL2_IMAGE_INCLUDE_DIR SDL_image.h
HINTS
ENV SDL2IMAGEDIR
ENV SDL2DIR
PATH_SUFFIXES SDL2
# path suffixes to search inside ENV{SDLDIR}
include/SDL2 include
PATHS ${SDL2_IMAGE_PATH}
)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(VC_LIB_PATH_SUFFIX lib/x64)
else()
set(VC_LIB_PATH_SUFFIX lib/x86)
endif()
find_library(SDL2_IMAGE_LIBRARY
NAMES SDL2_image
HINTS
ENV SDL2IMAGEDIR
ENV SDL2DIR
PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
PATHS ${SDL2_IMAGE_PATH}
)
if(SDL2_IMAGE_INCLUDE_DIR AND EXISTS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h")
file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+[0-9]+$")
file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+[0-9]+$")
file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+[0-9]+$")
string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_MAJOR "${SDL2_IMAGE_VERSION_MAJOR_LINE}")
string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_MINOR "${SDL2_IMAGE_VERSION_MINOR_LINE}")
string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_PATCH "${SDL2_IMAGE_VERSION_PATCH_LINE}")
set(SDL2_IMAGE_VERSION_STRING ${SDL2_IMAGE_VERSION_MAJOR}.${SDL2_IMAGE_VERSION_MINOR}.${SDL2_IMAGE_VERSION_PATCH})
unset(SDL2_IMAGE_VERSION_MAJOR_LINE)
unset(SDL2_IMAGE_VERSION_MINOR_LINE)
unset(SDL2_IMAGE_VERSION_PATCH_LINE)
unset(SDL2_IMAGE_VERSION_MAJOR)
unset(SDL2_IMAGE_VERSION_MINOR)
unset(SDL2_IMAGE_VERSION_PATCH)
endif()
set(SDL2_IMAGE_LIBRARIES ${SDL2_IMAGE_LIBRARY})
set(SDL2_IMAGE_INCLUDE_DIRS ${SDL2_IMAGE_INCLUDE_DIR})
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_image
REQUIRED_VARS SDL2_IMAGE_LIBRARIES SDL2_IMAGE_INCLUDE_DIRS
VERSION_VAR SDL2_IMAGE_VERSION_STRING)
# for backward compatibility
set(SDLIMAGE_LIBRARY ${SDL2_IMAGE_LIBRARIES})
set(SDLIMAGE_INCLUDE_DIR ${SDL2_IMAGE_INCLUDE_DIRS})
set(SDLIMAGE_FOUND ${SDL2_IMAGE_FOUND})
mark_as_advanced(SDL2_IMAGE_LIBRARY SDL2_IMAGE_INCLUDE_DIR)
My Cmake error output, I am a beginner with cmake btw, so laugh all you will.
CMakeFiles/mageengine.dir/Mafic/mafic.cpp.o: In function `load_image(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
mafic.cpp:(.text+0x2c): undefined reference to `IMG_Load'
mafic.cpp:(.text+0x43): undefined reference to `SDL_DisplayFormat'
CMakeFiles/mageengine.dir/Mafic/mafic.cpp.o: In function `init()':
mafic.cpp:(.text+0x133): undefined reference to `SDL_SetVideoMode'
mafic.cpp:(.text+0x152): undefined reference to `TTF_Init'
mafic.cpp:(.text+0x17c): undefined reference to `Mix_OpenAudio'
mafic.cpp:(.text+0x19e): undefined reference to `SDL_WM_SetCaption'
CMakeFiles/mageengine.dir/Mafic/mafic.cpp.o: In function `load_files()':
mafic.cpp:(.text+0x21c): undefined reference to `TTF_OpenFont'
mafic.cpp:(.text+0x25b): undefined reference to `Mix_LoadMUS'
mafic.cpp:(.text+0x298): undefined reference to `Mix_LoadWAV_RW'
mafic.cpp:(.text+0x2bf): undefined reference to `Mix_LoadWAV_RW'
mafic.cpp:(.text+0x2e6): undefined reference to `Mix_LoadWAV_RW'
mafic.cpp:(.text+0x30d): undefined reference to `Mix_LoadWAV_RW'
CMakeFiles/mageengine.dir/Mafic/mafic.cpp.o: In function `clean_up()':
mafic.cpp:(.text+0x3ba): undefined reference to `Mix_FreeChunk'
mafic.cpp:(.text+0x3c9): undefined reference to `Mix_FreeChunk'
mafic.cpp:(.text+0x3d8): undefined reference to `Mix_FreeChunk'
mafic.cpp:(.text+0x3e7): undefined reference to `Mix_FreeChunk'
mafic.cpp:(.text+0x3f6): undefined reference to `Mix_FreeMusic'
mafic.cpp:(.text+0x405): undefined reference to `TTF_CloseFont'
mafic.cpp:(.text+0x40a): undefined reference to `Mix_CloseAudio'
mafic.cpp:(.text+0x40f): undefined reference to `TTF_Quit'
collect2: error: ld returned 1 exit status
CMakeFiles/mageengine.dir/build.make:197: recipe for target 'mageengine' failed
make[2]: *** [mageengine] Error 1
CMakeFiles/Makefile2:75: recipe for target 'CMakeFiles/mageengine.dir/all' failed
make[1]: *** [CMakeFiles/mageengine.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2
Ok, I seem to have worked out the kinks. A magnitude harder than I led myself and others to believe.. - Probably did it the wrong way, but doesn't seem like many are going about it the way I am. I just went through and linked the libraries in my cmake file by doing this target_link_libraries(loaders -lSDLmain) target_link_libraries(loaders -lSDL) target_link_libraries(loaders -lSDL2_ttf) target_link_libraries(loaders -lSDL2_mixer) and downloading and istalling libs as needed. All this being said, i still have many problems, but i think it's a step closer.

Building error in ROS environment (catkin)

I want to build my project in catkin workspace. After executing catkin_make i got these errors:
6:11: error: ‘vector’ is not a member of ‘cv’
cv::vector<cv::Point> points;
6:31: error: expected primary-expression before ‘>’ token
cv::vector<cv::Point> points;
9:77: error: no matching function for call to ‘std::vector<Eigen::Matrix<double, 3, 1>, Eigen::aligned_allocator<Eigen::Matrix<double, 3, 1> > >::push_back(cv::Point)’
/catkin_ws/src/rgbd_calibration/src/rgbd_calibration/calibration_test.cpp:1123:113: error: no matching function for call to ‘fillConvexPoly(cv::Mat&, std::vector<Eigen::Matrix<double, 3, 1>, Eigen::aligned_allocator<Eigen::Matrix<double, 3, 1> > >&, cv::Scalar)’
cv::fillConvexPoly(tmp_image, points, cv::Scalar(c == 0 ? 128 : 0, c == 1 ? 128 : 0, c == 2 ? 128 : 0));
^
In file included from /opt/ros/kinetic/include/opencv-3.3.1-dev/opencv2/imgproc/imgproc.hpp:48:0,
from /opt/ros/kinetic/include/image_geometry/pinhole_camera_model.h:6,
I have build opencv 3.3.0, and also it finds `/opt/ros/kinetic/include/opencv-3.3.1-dev/opencv2/imgproc/imgproc.hpp:48:0,
I suspect that somthing has to do with opencv library but cant find out. Its my first try with ROS so any help would be welcomed
Makefile below:
cmake_minimum_required(VERSION 2.8.3)
project(rgbd_calibration)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS cmake_modules roscpp calibration_common geometry_msgs kinect
eigen_conversions camera_info_manager cv_bridge pcl_ros
image_transport)# swissranger_camera)
## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)
find_package(Boost REQUIRED)
find_package(Eigen REQUIRED)
find_package(PCL 1.7 REQUIRED)
find_package(OpenCV REQUIRED)
find_package(OpenMP REQUIRED)
find_package(Ceres REQUIRED)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
## Uncomment this if the package has a setup.py. This macro ensures
## modules and scripts declared therein get installed
# catkin_python_setup()
#######################################
## Declare ROS messages and services ##
#######################################
## Generate messages in the 'msg' folder
add_message_files(
FILES
Acquisition.msg
)
## Generate services in the 'srv' folder
# add_service_files(
# FILES
# Service1.srv
# Service2.srv
# )
## Generate added messages and services with any dependencies listed here
generate_messages(
DEPENDENCIES
std_msgs
)
###################################################
## Declare things to be passed to other projects ##
###################################################
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
INCLUDE_DIRS include
LIBRARIES interactive_checkerboard_finder rgbd_calibration
CATKIN_DEPENDS roscpp calibration_common geometry_msgs kinect
eigen_conversions camera_info_manager cv_bridge pcl_ros image_transport
DEPENDS eigen3 pcl opencv2
)
###########
## Build ##
###########
## Specify additional locations of header files
include_directories(include
${catkin_INCLUDE_DIRS}
${EIGEN_INCLUDE_DIRS}
${PCL_INCLUDE_DIRS}
${CERES_INCLUDE_DIRS}
)
## Declare a cpp library
add_library(rgbd_calibration
src/rgbd_calibration/calibration.cpp include/rgbd_calibration/calibration.h
include/rgbd_calibration/globals.h
src/rgbd_calibration/depth_undistortion_estimation.cpp include/rgbd_calibration/depth_undistortion_estimation.h
src/rgbd_calibration/checkerboard_views.cpp include/rgbd_calibration/checkerboard_views.h
src/rgbd_calibration/checkerboard_views_extractor.cpp include/rgbd_calibration/checkerboard_views_extractor.h
src/rgbd_calibration/publisher.cpp include/rgbd_calibration/publisher.h
)
add_executable(rgbd_offline_calibration
src/rgbd_calibration/calibration_node.cpp include/rgbd_calibration/calibration_node.h
src/rgbd_calibration/offline_calibration_node.cpp include/rgbd_calibration/offline_calibration_node.h
)
#add_executable(simulation
# src/rgbd_calibration/simulation_node.cpp include/rgbd_calibration/simulation_node.h
#)
add_executable(test_calibration
src/rgbd_calibration/test_node.cpp include/rgbd_calibration/test_node.h
src/rgbd_calibration/calibration_test.cpp include/rgbd_calibration/calibration_test.h
)
add_executable(data_collection
src/rgbd_calibration/data_collection_node.cpp
)
## Add dependencies to the executable
# add_dependencies(calibration_node ${PROJECT_NAME})
## Specify libraries to link a library or executable target against
target_link_libraries(rgbd_calibration
${catkin_LIBRARIES}
${PCL_LIBRARIES}
${OpenCV_LIBS}
${CERES_LIBRARIES}
)
target_link_libraries(rgbd_offline_calibration
rgbd_calibration
${catkin_LIBRARIES}
${PCL_LIBRARIES}
${OpenCV_LIBS}
${CERES_LIBRARIES}
)
#target_link_libraries(simulation
# rgbd_calibration
# ${catkin_LIBRARIES}
# ${PCL_LIBRARIES}
# ${OpenCV_LIBS}
# ${CERES_LIBRARIES}
#)
target_link_libraries(test_calibration
rgbd_calibration
${catkin_LIBRARIES}
${PCL_LIBRARIES}
${OpenCV_LIBS}
${CERES_LIBRARIES}
)
target_link_libraries(data_collection
${catkin_LIBRARIES}
${PCL_LIBRARIES}
${OpenCV_LIBS}
)
#############
## Install ##
#############
## Mark executable scripts (Python etc.) for installation
## not required for python when using catkin_python_setup()
# install(PROGRAMS
# scripts/my_python_script
# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )
## Mark executables and/or libraries for installation
# install(TARGETS calibration calibration_node
# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )
## Mark cpp header files for installation
# install(DIRECTORY include/${PROJECT_NAME}/
# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
# FILES_MATCHING PATTERN "*.h"
# PATTERN ".svn" EXCLUDE
# )
## Mark other files for installation (e.g. launch and bag files, etc.)
# install(FILES
# # myfile1
# # myfile2
# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
# )
#############
## Testing ##
#############
## Add gtest based cpp test target and link libraries
# catkin_add_gtest(${PROJECT_NAME}-test test/polynomial_undistortion_matrix_multifit_test.cpp)
# if(TARGET ${PROJECT_NAME}-test)
# target_link_libraries(${PROJECT_NAME}-test
# ${catkin_LIBRARIES}
# ${PCL_LIBRARIES}
# ${OpenCV_LIBS}
# ${CERES_LIBRARIES})
# endif()
## Add folders to be run by python nosetests
# catkin_add_nosetests(test)
You need to use STL's std::vector<>, CV does not have a vector implementation:
#include <vector>
...
std::vector<cv::Point> points;
...

docopt linker error for example program

I am trying to compile the example code from the github page of docopt. I am getting a linker error though:
/tmp/test-d3ed6b.o: In function `main':
test.cpp:(.text+0xf3): undefined reference to `docopt::docopt(std::string const&, std::vector<std::string, std::allocator<std::string> > const&, bool, std::string const&, bool)'
test.cpp:(.text+0x1c8): undefined reference to `docopt::operator<<(std::ostream&, docopt::value const&)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I have a file test.cpp and a directory docopt with all the docopt files in it.
test.cpp:
#include <iostream>
#include "docopt/docopt.h"
static const char USAGE[] =
R"(Naval Fate.
Usage:
naval_fate ship new <name>...
naval_fate ship <name> move <x> <y> [--speed=<kn>]
naval_fate ship shoot <x> <y>
naval_fate mine (set|remove) <x> <y> [--moored | --drifting]
naval_fate (-h | --help)
naval_fate --version
Options:
-h --help Show this screen.
--version Show version.
--speed=<kn> Speed in knots [default: 10].
--moored Moored (anchored) mine.
--drifting Drifting mine.
)";
int main(int argc, const char** argv)
{
std::map<std::string, docopt::value> args
= docopt::docopt(USAGE,
{ argv + 1, argv + argc },
true, // show help if requested
"Naval Fate 2.0"); // version string
for(auto const& arg : args) {
std::cout << arg.first << arg.second << std::endl;
}
return 0;
}
what is with that error? How can I fix that? I have tried clang-3.5 and g++
I ran into this as well.
I resolved the problem using cmake and some specific configuration in my CMakeLists.txt. The following configuration worked for me:
cmake_minimum_required (VERSION 3.5)
project(my_project)
include(ExternalProject)
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
set(DOCOPT_ROOT ${PROJECT_SOURCE_DIR}/external/docopt)
set(DOCOPT_INCLUDE_DIRS ${DOCOPT_ROOT}/include/docopt)
set(DOCOPT_LIBRARIES ${DOCOPT_ROOT}/lib/libdocopt.a)
set(docopt_INSTALL_DIR "${DOCOPT_ROOT}")
set(docopt_CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${docopt_INSTALL_DIR})
ExternalProject_Add(docopt
PREFIX ${DOCOPT_ROOT}
GIT_REPOSITORY https://github.com/docopt/docopt.cpp.git
BINARY_DIR ${DOCOPT_ROOT}
INSTALL_DIR ${DOCOPT_ROOT}
CMAKE_ARGS ${docopt_CMAKE_ARGS}
LOG_DOWNLOAD ON
LOG_CONFIGURE ON
LOG_BUILD ON
LOG_INSTALL ON
)
add_library(libdocopt STATIC IMPORTED)
set_target_properties(libdocopt PROPERTIES IMPORTED_LOCATION ${DOCOPT_LIBRARIES})
add_dependencies(libdocopt docopt)
include_directories(${PROJECT_SOURCE_DIR})
include_directories(${DOCOPT_INCLUDE_DIRS})
file(GLOB projector_src
"*.h"
"*.cpp"
)
add_executable(my_project ${my_project_src})
target_link_libraries(projector libdocopt)
Obviously, you don't need to use cmake, but instead you'll need to either put the source for docopt.cpp in with your own code or else you'll need to tell the linker where to look for it. cmake does take care of this for you, but it's one more thing to worry about.
Modified Jeremiah Peschka's answer to work out of the box independently of any other sources.
Project structure:
├── CMakeLists.txt
├── build
└── main.cpp
CMakeLists.txt
cmake_minimum_required (VERSION 3.5)
project(my_project)
include(ExternalProject)
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
set(DOCOPT_ROOT ${PROJECT_SOURCE_DIR}/external/docopt)
set(DOCOPT_INCLUDE_DIRS ${DOCOPT_ROOT}/include/docopt)
set(DOCOPT_LIBRARIES ${DOCOPT_ROOT}/lib/libdocopt.a)
set(docopt_INSTALL_DIR "${DOCOPT_ROOT}")
set(docopt_CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${docopt_INSTALL_DIR})
ExternalProject_Add(docopt
PREFIX ${DOCOPT_ROOT}
GIT_REPOSITORY https://github.com/docopt/docopt.cpp.git
BINARY_DIR ${DOCOPT_ROOT}
INSTALL_DIR ${DOCOPT_ROOT}
CMAKE_ARGS ${docopt_CMAKE_ARGS}
LOG_DOWNLOAD ON
LOG_CONFIGURE ON
LOG_BUILD ON
LOG_INSTALL ON
)
add_library(libdocopt STATIC IMPORTED)
set_target_properties(libdocopt PROPERTIES IMPORTED_LOCATION ${DOCOPT_LIBRARIES})
add_dependencies(libdocopt docopt)
include_directories(${PROJECT_SOURCE_DIR})
include_directories(${DOCOPT_INCLUDE_DIRS})
file(GLOB src
"*.h"
"*.cpp"
)
add_executable(my_project ${src})
target_link_libraries(my_project libdocopt)

RCC Parse Error during make with cmake and Qt4

I have a small Qt4 project which I want to build with cmake.
It has a QTcpServer and a QThread, which both include the Q_OBJECT macro.
When I'm running make I always get an RCC Parse Error after generating qrc_tcpserver.cxx.
The exact failure output is:
[ 9%] Generating qrc_tcpserver.cxx
RCC Parse Error: '/home/path/server/include/tcpserver.h' Line: 1 Column: 1 [error occurred while parsing element]
make[2]: *** [qrc_tcpserver.cxx] Fehler 1
make[1]: *** [CMakeFiles/TcpServer.dir/all] Fehler 2
make: *** [all] Fehler 2
My cmake file looks like this:
set(PROJECT_NAME TcpServer)
PROJECT(${PROJECT_NAME} )
cmake_minimum_required(VERSION 2.6)
# FOR QT4
find_package(Qt4 REQUIRED COMPONENTS QtCore QtNetwork)
SET(CMAKE_PACKAGE_QTGUI FALSE)
SET( QT_WRAP_CPP TRUE )
set(QT_USE_QTXML TRUE)
# ENABLE WARNINGS
ADD_DEFINITIONS( -Wall )
#FOR GOOGLETEST
if(test)
find_package(GTest REQUIRED)
enable_testing()
endif()
set(QT_USE_QTNETWORK TRUE)
set(INCLUDES ${PROJECT_SOURCE_DIR}/include)
set(${PROJECT_NAME}_Qt_SRC
${INCLUDES}/tcpworkerthread.h
${INCLUDES}/tcpserver.h
)
set(${PROJECT_NAME}_Qt_UI
)
set(${PROJECT_NAME}_Qt_RES
)
INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS})
IF(QT_WRAP_CPP)
MESSAGE("Wrap cpp!")
QT4_WRAP_CPP(${PROJECT_NAME}_MOC_CPP ${${PROJECT_NAME}_Qt_SRC})
ENDIF(QT_WRAP_CPP)
QT4_WRAP_UI(${PROJECT_NAME}_UI_CPP ${${PROJECT_NAME}_Qt_UI})
QT4_ADD_RESOURCES(${PROJECT_NAME}_RES_H ${${PROJECT_NAME}_Qt_SRC})
if(test)
include_directories(${GTEST_INCLUDE_DIRS} ${INCLUDES} ${QT_QTNETWORK_INCLUDE_DIR})
else()
include_directories(${INCLUDES} ${QT_QTNETWORK_INCLUDE_DIR})
endif()
if(test)
set(${PROJECT_NAME}_SRC_TEST
src_test/main.cpp
src_test/tcpservertest.cpp
src_test/tcpworkerthreadtest.cpp
)
set(PROJECT_TEST_NAME "${PROJECT_NAME}_test")
set(${PROJECT_NAME}_SRC
src/tcpserver.cpp
src/tcpworkerthread.cpp
)
else()
set(${PROJECT_NAME}_SRC
main.cpp
src/tcpserver.cpp
src/tcpworkerthread.cpp
)
endif()
set(${PROJECT_NAME}_LIB
${QT_LIBRARIES}
${QT_QTNETWORK_LIBRARIES}
)
if(test)
add_library(${PROJECT_NAME} STATIC ${${PROJECT_NAME}_SRC} )
add_executable(${PROJECT_TEST_NAME} ${${PROJECT_NAME}_SRC_TEST})
target_link_libraries(${PROJECT_TEST_NAME} ${PROJECT_NAME} ${${PROJECT_NAME}_LIB} ${GTEST_BOTH_LIBRARIES} pthread)
add_test(${PROJECT_TEST_NAME} ${PROJECT_TEST_NAME})
else()
add_executable( ${PROJECT_NAME} ${${PROJECT_NAME}_SRC} ${${PROJECT_NAME}_MOC_CPP} ${${PROJECT_NAME}_UI_CPP} ${${PROJECT_NAME}_RES_H})
target_link_libraries( ${PROJECT_NAME} ${${PROJECT_NAME}_LIB} )
endif()
I execute it without test variable, so this is set to false(I use it for generating gtest, which is not so important for me, just for playing around).
Any idea where my failure is?
I'm not very familar with CMake, but it seems you're feeding a wrong list of files to QT4_ADD_RESOURCES.
The line
QT4_ADD_RESOURCES(${PROJECT_NAME}_RES_H ${${PROJECT_NAME}_Qt_SRC})
should probably be
QT4_ADD_RESOURCES(${PROJECT_NAME}_RES_H ${${PROJECT_NAME}_Qt_RES})