In short: I can't link my program that uses CPLEX with CMake, the linker doesn't seem to find a CPLEX library (cplex), but finds some others (ilocplex). From the command line, it does work.
Detailed:
For the program using CPLEX:
#include <ilcplex/ilocplex.h>
int main(int argc, char *argv[]) {
IloEnv env;
IloModel model(env);
IloCplex cplex(model);
return 0;
}
I have the following CMakeLists.txt:
cmake_minimum_required(VERSION 3.17)
project(myprog C CXX)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
find_package(CPLEX)
if (CPLEX_FOUND)
add_definitions(-DIL_STD)
else()
message (FATAL_ERROR "CPLEX not found!")
endif()
add_executable(myprog src/main.cpp )
target_include_directories(myprog PUBLIC ${CPLEX_INCLUDE_DIRS})
target_link_libraries(myprog PUBLIC ${CPLEX_LIBRARIES})
set_target_properties(myprog PROPERTIES LINK_FLAGS "-lconcert -lilocplex -lcplex -lpthread -ldl")
and cmake/FindCPLEX.cmake:
set (CPLEX_DIR "/opt/ibm/ILOG/CPLEX_Studio_Community201")
if (CPLEX_INCLUDE_DIR)
set(CPLEX_FOUND TRUE)
set(CPLEX_INCLUDE_DIRS "${CPLEX_INCLUDE_DIR};${CPLEX_CONCERT_INCLUDE_DIR}" )
set(CPLEX_LIBRARIES "${CPLEX_ILO_LIBRARY};${CPLEX_CONCERT_LIBRARY};${CPLEX_LIBRARY};${CPLEX_PTHREAD_LIBRARY}" )
else (CPLEX_INCLUDE_DIR)
find_path(CPLEX_INCLUDE_DIR
NAMES ilcplex/cplex.h
PATHS "${CPLEX_DIR}/cplex/include"
)
find_path(CPLEX_INCLUDE_ILCPLEX
NAMES cplex.h
PATHS "${CPLEX_DIR}/cplex/include/ilcplex"
)
find_path(CPLEX_CONCERT_INCLUDE_DIR
NAMES ilconcert/ilomodel.h
PATHS "${CPLEX_DIR}/concert/include"
)
find_path(CPLEX_INCLUDE_ILCONCERT
NAMES ilomodel.h
PATHS "${CPLEX_DIR}/concert/include/ilconcert"
)
find_library(CPLEX_LIBRARY
cplex
PATHS "${CPLEX_DIR}/cplex/lib/x86-64_sles10_4.1/static_pic"
"${CPLEX_DIR}/cplex/lib/x86-64_darwin/static_pic/"
"${CPLEX_DIR}/cplex/lib/x86-64_linux/static_pic"
)
find_library(CPLEX_ILO_LIBRARY
ilocplex
PATHS "${CPLEX_DIR}/cplex/lib/x86-64_sles10_4.1/static_pic"
"${CPLEX_DIR}/cplex/lib/x86-64_darwin/static_pic/"
"${CPLEX_DIR}/cplex/lib/x86-64_linux/static_pic"
)
find_library(CPLEX_CONCERT_LIBRARY
concert
PATHS "${CPLEX_DIR}/concert/lib/x86-64_linux/static_pic/"
"${CPLEX_DIR}/concert/lib/x86-64_sles10_4.1/static_pic"
"${CPLEX_DIR}/concert/lib/x86-64_darwin/static_pic/"
)
find_library( CPLEX_PTHREAD_LIBRARY
pthread
PATHS "/usr/lib"
"/usr/lib64"
"/lib"
"/lib64"
)
find_library( CPLEX_DL_LIBRARY
dl
PATHS "/usr/lib"
"/usr/lib64"
"/lib"
"/lib64"
)
set(CPLEX_COMPILER_FLAGS "-DIL_STD" CACHE STRING "Cplex Compiler Flags")
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(CPLEX DEFAULT_MSG
CPLEX_LIBRARY CPLEX_INCLUDE_DIR CPLEX_CONCERT_INCLUDE_DIR CPLEX_ILO_LIBRARY CPLEX_CONCERT_LIBRARY)
if(CPLEX_FOUND)
set(CPLEX_INCLUDE_DIRS "${CPLEX_INCLUDE_DIR};${CPLEX_CONCERT_INCLUDE_DIR};${CPLEX_INCLUDE_ILCPLEX};${CPLEX_INCLUDE_ILCONCERT}" )
set(CPLEX_LIBRARIES ${CPLEX_CONCERT_LIBRARY} ${CPLEX_ILOCPLEX_LIBRARY} ${CPLEX_LIBRARY} ${CPLEX_PTHREAD_LIBRARY} ${CPLEX_DL_LIBRARY})
endif(CPLEX_FOUND)
mark_as_advanced(CPLEX_INCLUDE_DIR CPLEX_LIBRARY CPLEX_CONCERT_INCLUDE_DIR CPLEX_ILO_LIBRARY CPLEX_CONCERT_LIBRARY CPLEX_PTHREAD_LIBRARY)
endif(CPLEX_INCLUDE_DIR)
message(STATUS "CPLEX_ILO_LIBRARY=${CPLEX_ILO_LIBRARY}")
message(STATUS "CPLEX_LIBRARIES=${CPLEX_LIBRARIES}")
message(STATUS "CPLEX_INCLUDE_DIRS=${CPLEX_INCLUDE_DIRS}")
message(STATUS "concert=${concert}")
message(STATUS "cplex=${cplex}")
The CPLEX related CMake output is
-- Found CPLEX: /opt/ibm/ILOG/CPLEX_Studio_Community201/cplex/lib/x86-64_linux/static_pic/libcplex.a
-- CPLEX_ILO_LIBRARY=/opt/ibm/ILOG/CPLEX_Studio_Community201/cplex/lib/x86-64_linux/static_pic/libilocplex.a
-- CPLEX_LIBRARIES=/opt/ibm/ILOG/CPLEX_Studio_Community201/concert/lib/x86-64_linux/static_pic/libconcert.a;/opt/ibm/ILOG/CPLEX_Studio_Community201/cplex/lib/x86-64_linux/static_pic/libcplex.a;/usr/lib/x86_64-linux-gnu/libpthread.so;/usr/lib/x86_64-linux-gnu/libdl.so
-- CPLEX_INCLUDE_DIRS=/opt/ibm/ILOG/CPLEX_Studio_Community201/cplex/include;/opt/ibm/ILOG/CPLEX_Studio_Community201/concert/include;/opt/ibm/ILOG/CPLEX_Studio_Community201/cplex/include/ilcplex;/opt/ibm/ILOG/CPLEX_Studio_Community201/concert/include/ilconcert
-- concert=
-- cplex=
The error is
/usr/bin/ld: cannot find -lconcert
/usr/bin/ld: cannot find -lilocplex
/usr/bin/ld: cannot find -lcplex
Without the last line in CMakeLists.txt, the error is
/usr/bin/ld: CMakeFiles/myprog.dir/src/main.cpp.o: in function `main':
/<my path>/src/main.cpp:7: undefined reference to `IloCplex::IloCplex(IloModel)'
that is the linker finds the class IloEnv in /opt/ibm/ILOG/CPLEX_Studio_Community201/concert/include/ilconcert/iloenv.h and IloModel in /opt/ibm/ILOG/CPLEX_Studio_Community201/concert/include/ilconcert/ilomodel.h but not IloCplex in /opt/ibm/ILOG/CPLEX_Studio_Community201/cplex/include/ilcplex/ilocplexi.h.
Compiling from the command line works (formatted here for ease of reading):
$ for f in src/*.cpp; do
... g++ -c -I/opt/ibm/ILOG/CPLEX_Studio_Community201/cplex/include
... -I/opt/ibm/ILOG/CPLEX_Studio_Community201/concert/include
... -Iinclude $f -o build/$(basename $f .cpp).o;
... done
$ unset OBJ_FILES
$ for i in build/*.o; do OBJ_FILES="$i $OBJ_FILES"; done
$ g++ -I/opt/ibm/ILOG/CPLEX_Studio_Community201/cplex/include
... -I/opt/ibm/ILOG/CPLEX_Studio_Community201/concert/include
... -Iinclude
... -L/opt/ibm/ILOG/CPLEX_Studio_Community201/cplex/lib/x86-64_linux/static_pic
... -L/opt/ibm/ILOG/CPLEX_Studio_Community201/concert/lib/x86-64_linux/static_pic
... $OBJ_FILES
... -o progr
... -lconcert -lilocplex -lcplex -lpthread -ldl
As Tsyvarev noted: instead of using CPLEX_ILOCPLEX_LIBRARY that is nowhere set, the variable CPLEX_ILO_LIBRARY should be used in the definition of CPLEX_LIBRARIES.
Related
I try to add a custom compiler to CMake and I have been using this answer to create it: Generic rule from makefile to CMake
When I use enable_languange(MYCOMPILER) this works, but then I have to add also set_target_properties() to be able to compile everything.
I wanted that the user can write his project with just
project(MyProject MYCOMPILER)
The files are copied in a global directory "/opt/amiga/utils/CMake" and the path also includes "/opt/amiga/utils", so CMake is able to find and process the files, which I confirmed by putting message statements in there.
but then I get an error from CMake:
CMake Error: Cannot determine link language for target "MyProject"
So what exactly is required that CMake is recognizing the linking stage as well?
CMakeDetermineAMIGA_CCompiler.cmake
set(AMIGA_COMPILER_NAME $ENV{CC})
if (NOT AMIGA_COMPILER_NAME)
set(AMIGA_COMPILER_NAME m68k-amigaos-gcc)
endif()
find_path(AMIGA_COMPILER_PATH
NAMES
"${AMIGA_COMPILER_NAME}"
"${AMIGA_COMPILER_NAME}.exe"
CMAKE_FIND_ROOT_PATH_BOTH
)
if ("${AMIGA_COMPILER_PATH}" STREQUAL "AMIGA_COMPILER_PATH-NOTFOUND")
message(FATAL_ERROR "'${AMIGA_COMPILER_NAME}' not found. Make sure that '${AMIGA_COMPILER_NAME}' is in PATH!")
endif ("${AMIGA_COMPILER_PATH}" STREQUAL "AMIGA_COMPILER_PATH-NOTFOUND")
# Remove the <path>/bin part
get_filename_component(AMIGA_PATH_PREFIX ${AMIGA_COMPILER_PATH} DIRECTORY)
set(AMIGA_PATH_PREFIX "${AMIGA_PATH_PREFIX}/")
find_program(
AMIGA_COMPILER
NAMES
"${AMIGA_COMPILER_NAME}"
"${AMIGA_COMPILER_NAME}.exe"
HINTS "${AMIGA_COMPILER_PATH}"
DOC "gcc Amiga OS 1.x"
)
if ("${AMIGA_COMPILER}" STREQUAL "AMIGA_COMPILER-NOTFOUND")
message(FATAL_ERROR "'${AMIGA_COMPILER_NAME}' not found. Make sure that '${AMIGA_COMPILER_NAME}[.exe]' is in PATH!")
endif ("${AMIGA_COMPILER}" STREQUAL "AMIGA_COMPILER-NOTFOUND")
mark_as_advanced(CMAKE_${ASM_DIALECT}_COMPILER)
set(CMAKE_AMIGA_C_COMPILER "${AMIGA_COMPILER}")
set(CMAKE_AMIGA_C_SOURCE_FILE_EXTENSIONS c;C;cpp;cxx;CPP;CXX;cc;CC)
set(CMAKE_AMIGA_C_OUTPUT_EXTENSION .o)
set(CMAKE_AMIGA_C_COMPILER_ENV_VAR "CC")
# Configure variables set in this file for fast reload later on
configure_file(${CMAKE_CURRENT_LIST_DIR}/CMakeAMIGA_CCompiler.cmake.in
${CMAKE_PLATFORM_INFO_DIR}/CMakeAMIGA_CCompiler.cmake)
CMakeAMIGA_CInformation.cmake
SET(BUILD_SHARED_LIBS OFF)
set(CMAKE_AMIGA_C_FLAGS "--save-temps -Wall -pedantic -mcrt=nix13 -fno-exceptions -fno-rtti")
set(CMAKE_AMIGA_C_FLAGS_DEBUG "${CMAKE_ASM_FLAGS} -D_DEBUG -g -mregparm")
set(CMAKE_AMIGA_C_FLAGS_RELEASE "${CMAKE_ASM_FLAGS} --O2 -mregparm")
set(CMAKE_INCLUDE_FLAG_AMIGA_C "-I")
if(NOT CMAKE_AMIGA_C_COMPILE_OBJECT)
message(STATUS "Enable AMIGA_C")
set(CMAKE_AMIGA_C_COMPILE_OBJECT "<CMAKE_AMIGA_C_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> <SOURCE>")
endif()
if(NOT CMAKE_AMIGA_C_CREATE_STATIC_LIBRARY)
set(CMAKE_AMIGA_C_CREATE_STATIC_LIBRARY
"<CMAKE_AR> cr <TARGET> <LINK_FLAGS> <OBJECTS> "
"<CMAKE_RANLIB> <TARGET> ")
endif()
if(NOT DEFINED CMAKE_AMIGA_C_ARCHIVE_CREATE)
set(CMAKE_AMIGA_C_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>")
endif()
if(NOT DEFINED CMAKE_AMIGA_C_ARCHIVE_APPEND)
set(CMAKE_AMIGA_C_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>")
endif()
if(NOT DEFINED CMAKE_AMIGA_C_ARCHIVE_FINISH)
set(CMAKE_AMIGA_C_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
endif()
if(NOT CMAKE_AMIGA_C_LINK_EXECUTABLE)
set(CMAKE_AMIGA_C_LINK_EXECUTABLE
"<CMAKE_AMIGA_C_COMPILER> <FLAGS> <CMAKE_AMIGA_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
endif()
set(CMAKE_AMIGA_C_INFORMATION_LOADED 1)
CMakeAMIGA_CCompiler.cmake.in
set(CMAKE_AMIGA_C_COMPILER "#CMAKE_AMIGA_C_COMPILER#")
set(CMAKE_AMIGA_C_COMPILER_LOADED 1)
set(CMAKE_AMIGA_C_SOURCE_FILE_EXTENSIONS #CMAKE_AMIGA_C_DIALECT_SOURCE_FILE_EXTENSIONS#)
set(CMAKE_AMIGA_C_OUTPUT_EXTENSION #CMAKE_AMIGA_C_OUTPUT_EXTENSION#)
set(CMAKE_AMIGA_C_COMPILER_ENV_VAR "#CMAKE_AMIGA_C_DIALECT_COMPILER_ENV_VAR#")
CMakeTestAMIGA_CCompiler.cmake
set(CMAKE_AMIGA_C_COMPILER_WORKS 1 CACHE INTERNAL "")
CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(Test AMIGA_C)
set(TARGET ${PROJECT_NAME})
set(SOURCES
main.cpp
)
add_executable(${TARGET} ${SOURCES})
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.
I have the following cmake file to download, build and install zlib:
cmake_minimum_required ( VERSION 2.8.7 )
include (ExternalProject)
if(UNIX)
# An external project for zlib
SET (GIT_URL https://github.com/madler/zlib.git)
SET (ZLIB_INSTALL ${CMAKE_CURRENT_BINARY_DIR})
SET (ZLIB_INCLUDE ${CMAKE_BINARY_DIR}/include/zlib)
SET (ZLIB_STATIC ${CMAKE_BINARY_DIR}/lib/libz.a )
ExternalProject_Add(zlib
PREFIX zlib
GIT_REPOSITORY ${GIT_URL}
INSTALL_DIR ${ZLIB_INSTALL}
PATCH_COMMAND ${CMAKE_COMMAND} -E remove <SOURCE_DIR>/zconf.h
BUILD_IN_SOURCE 1
PATCH_COMMAND ""
CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=<INSTALL_DIR> --includedir=${ZLIB_INCLUDE}
)
SET (ZLIB_INCLUDE_DIR ${ZLIB_INSTALL}/include/zlib)
SET (ZLIB_LIBRARY "${ZLIB_INSTALL}")
ADD_LIBRARY (ZLIB_LIB STATIC IMPORTED DEPENDS zlib)
SET_TARGET_PROPERTIES (ZLIB_LIB PROPERTIES IMPORTED_LOCATION "${ZLIB_STATIC}")
endif(UNIX)
But this cmake file only install zlib. I want also install minizip. Minizip is "part of zlib". In the zlib repository has a directory that has minizip.
How can I also install minizip in the same cmake file? Is it possible?
The minizip is inside zlib repository:
- zlib
- contrib
- minizip
- ....
- ...
- ...
I have cmake file to install minizip:
cmake_minimum_required(VERSION 2.8)
project(minizip)
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
set(BUILD_SHARED_LIBS OFF)
find_package (ZLIB REQUIRED)
if (ZLIB_FOUND)
set(ZLIB_LIBRARY ${CMAKE_BINARY_DIR}/ZLIB/src/ZLIB/contrib)
SET (minizip ${CMAKE_BINARY_DIR}/lib/minizip)
if(CMAKE_HOST_APPLE)
set(PLATFORM __APPLE__)
elseif(CMAKE_HOST_UNIX)
set(PLATFORM unix)
elseif(CMAKE_HOST_WIN32)
set(PLATFORM _WIN32)
else(CMAKE_HOST_APPLE)
message(FATAL_ERROR "Not supported Platform")
endif(CMAKE_HOST_APPLE)
add_definitions(-D${PLATFORM})
set(SOURCE
${ZLIB_LIBRARY}/minizip/ioapi.c
${ZLIB_LIBRARY}/minizip/miniunz.c
${ZLIB_LIBRARY}/minizip/minizip.c
${ZLIB_LIBRARY}/minizip/unzip.c
${ZLIB_LIBRARY}/minizip/zip.c
)
if(WIN32)
set(SOURCE ${SOURCE} ${ZLIB_LIBRARY}/minizip/iowin32.c)
endif(WIN32)
set(HEADERS
${ZLIB_LIBRARY}/minizip/crypt.h
${ZLIB_LIBRARY}/minizip/ioapi.h
${ZLIB_LIBRARY}/minizip/miniunz.h
${ZLIB_LIBRARY}/minizip/unzip.h
)
if(WIN32)
set(HEADERS ${HEADERS} ${ZLIB_LIBRARY}/minizip/iowin32.h)
endif(WIN32)
add_library(minizip ${SOURCE} ${HEADERS})
target_link_libraries(minizip PUBLIC "-static" ZLIB_STATIC)
add_dependencies ( minizip zlib)
install(
TARGETS minizip EXPORT minizip-exports
INCLUDES DESTINATION "include"
RUNTIME DESTINATION "bin"
LIBRARY DESTINATION "lib"
ARCHIVE DESTINATION "lib"
)
install(
FILES ${HEADERS}
DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/include/minizip"
)
ADD_LIBRARY (MINIZIP_LIB STATIC IMPORTED DEPENDS minizip)
SET_TARGET_PROPERTIES (MINIZIP_LIB PROPERTIES IMPORTED_LOCATION ${minizip})
endif()
I want before install minizip, install zlib.
But when I run
cmake ..
I have the following error:
Make Error at modules/minizip.cmake:50 (add_library):
Cannot find source file:
/home/lais/Imagens/agent/build/ZLIB/src/ZLIB/contrib/minizip/ioapi.c
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
Call Stack (most recent call first):
CMakeLists.txt:59 (include)
CMake Error: Cannot determine link language for target "minizip".
CMake Error: CMake can not determine linker language for target: minizip
And I have a top level cmake, that call for this two modules:
cmake_minimum_required( VERSION 2.8.7 )
project( project )
# version number
set ( VERSION_MAJOR 0 )
set ( VERSION_MINOR 0 )
# cpr requires c++11
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc")
# src : main + jsoncpp library
file ( GLOB SOURCES src/project/*.cpp )
# src : collect functions - depend on OS
if ( WIN32 )
file ( GLOB SOURCES ${SOURCES} src/project/windows/*.cpp )
else () # if( UNIX )
file ( GLOB SOURCES ${SOURCES} src/project/linux/*.cpp )
endif ()
# src : curl requests
# options for cpr
# avoid experimental use of openssl
option( CMAKE_USE_OPENSSL "Use OpenSSL code. Experimental" OFF )
# avoid building tests
option( BUILD_CPR_TESTS "Set to ON to build cpr tests." OFF )
# options for curl
# avoid building tests
option( BUILD_CURL_TESTS "Set to ON to build cURL tests." OFF )
# avoid running tests - set ON again in download version or if errors occur
option( RUN_CURL_TESTS "Set to ON to run cURL tests." OFF )
add_subdirectory ( lib/cpr )
include_directories ( ${CPR_INCLUDE_DIRS} )
include_directories ( ${CURL_INCLUDE_DIRS} )
# src : DtWinVer - Windows Version/Edition class
if ( WIN32 )
add_subdirectory ( lib/dtwinver )
endif ()
# headers
include_directories ( "include" )
include_directories ( "${CMAKE_BINARY_DIR}/include" )
# scr = libboost
include ( "modules/boost.cmake" )
# src = zlib
include ( "modules/zlib.cmake" )
# src = minizip
include ( "modules/minizip.cmake" )
# compile
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY "../bin" )
add_executable ( project-v${VERSION_MAJOR}.${VERSION_MINOR} ${SOURCES} )
target_link_libraries ( project-v${VERSION_MAJOR}.${VERSION_MINOR} ${CPR_LIBRARIES} ${CURL_LIBRARIES} ${FILESYSTEM_LIB} ${SYSTEM_LIB} ${REGEX_LIB} ${PROGRAM_OPTIONS_LIB} ${ZLIB_STATIC} ${minizip})
add_dependencies ( project-v${VERSION_MAJOR}.${VERSION_MINOR} Boost)
add_dependencies ( project-v${VERSION_MAJOR}.${VERSION_MINOR} zlib)
add_dependencies ( project-v${VERSION_MAJOR}.${VERSION_MINOR} minizip)
if ( WIN32 )
target_link_libraries ( project-v${VERSION_MAJOR}.${VERSION_MINOR} dtwinver )
else ()
# libudev
target_link_libraries ( project-v${VERSION_MAJOR}.${VERSION_MINOR} udev )
endif ()
Looks your source package is not complete.
minizip is just simple a single file minizip.c. Why do you need cmake? Just compile it and link with zlib and everything will be fine.
I have gotten the two libraries necessary for my cpp application.
https://github.com/rbock/sqlpp11
https://github.com/rbock/sqlpp11-connector-mysql
I have them downloaded along with libmysqlclient-dev and the date library. All of the library tests work when I create a build dir in each of the project cmake .. and make and run make tests.
I import both the libraries in the root directory of the project using import_library(), and there are no errors with cmake .. from the build dir. When I run a make the code is unable to find the includes for <sqlpp11/sqlpp11.h> even though the cmake .. runs ok. The following is my root CMakeLists.txt and my src CMakeLists.txt.
cmake_minimum_required(VERSION 3.5)
project(mysql_sample)
set(HinnantDate_ROOT_DIR "${PROJECT_SOURCE_DIR}/date")
find_library(sqlpp11 REQUIRED)
include_directories(${sqlpp11_INCLUDE_DIRS})
find_library(sqlpp11-connector-mysql REQUIRED)
include_directories(${sqlpp11-connector-mysql_INCLUDE_DIRS})
include_directories(${PROJECT_SOURCE_DIR}/include)
add_subdirectory(include)
add_subdirectory(src)
add_subdirectory(test)
and
add_executable(mysql_sample main.cpp)
target_link_libraries(mysql_sample ${sqlpp11_LIBRARIES})
target_link_libraries(mysql_sample ${sqlpp11-connector-mysql_LIBRARIES})
Edit 1
In response to the comment the error is
Maker Error at /usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find Sqlpp11-connector-mysql (missing:
sqlpp11-connector-mysql_INCLUDE_DIR)
Call Stack (most recent call first):
/usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
CMake/FindSqlpp11-connector-mysql.cmake:7 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:15 (find_package)
-- Configuring incomplete, errors occurred!
See also "/home/andrew/cpp_work/sql_sample_project/build/CMakeFiles/CMakeOutput.log".
See also "/home/andrew/cpp_work/sql_sample_project/build/CMakeFiles/CMakeError.log".
With CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(mysql_sample)
set(HinnantDate_ROOT_DIR "${PROJECT_SOURCE_DIR}/date")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/CMake)
find_package(Sqlpp11 REQUIRED)
include_directories(${sqlpp11_INCLUDE_DIRS})
set(include_dir "${PROJECT_SOURCE_DIR}/include")
file(GLOB_RECURSE sqlpp_headers ${include_dir}/*.h ${SQLPP11_INCLUDE_DIR}/*.h)
include_directories(${include_dir})
find_package(Sqlpp11-connector-mysql REQUIRED)
include_directories(${sqlpp11-connector-mysql_INCLUDE_DIRS})
file(GLOB_RECURSE sqlpp11-connector-mysql_headers ${include_dir}/*.h ${sqlpp11-connector-mysql_INCLUDE_DIR}/*.h)
include_directories(${include_dir})
add_executable(mysql_sample src/main.cpp)
target_link_libraries(mysql_sample ${sqlpp11_LIBRARIES})
target_link_libraries(mysql_sample ${sqlpp11-connector-mysql_LIBRARIES})
include_directories(${PROJECT_SOURCE_DIR}/include)
add_subdirectory(include)
add_subdirectory(src)
add_subdirectory(test)
and FindSqlpp11.cmake
find_path(SQLPP11_INCLUDE_DIR sqlpp11.h
${PROJECT_SOURCE_DIR}/sqlpp11
${PROJECT_SOURCE_DIR}/include/sqlpp11
)
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Sqlpp11 DEFAULT_MSG SQLPP11_INCLUDE_DIR)
mark_as_advanced(SQLPP11_INCLUDE_DIR)
and FindSqlpp11-connector-mysql.cmake
find_path(Sqlpp11-connector-mysql_INCLUDE_DIR sqlpp11-connector-mysql.h
${PROJECT_SOURCE_DIR}/sqlpp11-connector-mysql
${PROJECT_SOURCE_DIR}/include/sqlpp11-connector-mysql
)
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Sqlpp11-connector-mysql DEFAULT_MSG sqlpp11-connector-mysql_INCLUDE_DIR)
mark_as_advanced(Sqlpp11-connector-mysql_INCLUDE_DIR)
Why is there an error here and am I on the right track?
Edit 2
I managed to get the above working, my issue was that I was not installing properly. I now get the following error from this code.
main.cpp:(.text+0x124): undefined reference to `sqlpp::mysql::connection::connection(std::shared_ptr<sqlpp::mysql::con
nection_config> const&)'
main.cpp:(.text+0x12e): undefined reference to `sqlpp::mysql::connection::~connection()'
collect2: error: ld returned 1 exit status
CMakeFiles/mysql_sample.dir/build.make:94: recipe for target 'mysql_sample' failed
make[2]: *** [mysql_sample] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/mysql_sample.dir/all' failed
make[1]: *** [CMakeFiles/mysql_sample.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
Code:
include "TabSample.h"
#include <sqlpp11/sqlpp11.h>
#include <sqlpp11/mysql/mysql.h>
namespace mysql = sqlpp::mysql;
int main()
{
auto config = std::make_shared<mysql::connection_config>();
config->user = "root";
config->database = "sqlpp_mysql";
config->debug = true;
mysql::connection db(config);
TabSample tab;
for(const auto& row : db.run(sqlpp::select(all_of(tab)).from(tab).unconditionally()))
{
std::cerr << "row.alpha: " << row.alpha << ", row.beta: " << row.beta << ", row.gamma: " << row.gamma << std::endl;
};
return 0;
}
I am using gcc 4.9 and there are no errors with the make / make install, am I missing something in my CMakeLists.txt?
cmake_minimum_required(VERSION 3.5)
project(mysql_sample)
set(HinnantDate_ROOT_DIR "/usr/local/lib/date")
include_directories(/usr/local/lib/date)
if(UNIX)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=gnu++0x")
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/CMake)
set(SQLPP11_INCLUDE_DIR /usr/local/include)
find_package(Sqlpp11 REQUIRED)
add_executable(mysql_sample src/main.cpp)
target_link_libraries(mysql_sample ${sqlpp11_LIBRARIES})
target_link_libraries(mysql_sample ${sqlpp11-connector-mysql_LIBRARIES})
include_directories(${PROJECT_SOURCE_DIR}/include)
add_subdirectory(include)
add_subdirectory(src)
add_subdirectory(test)
CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(mysql_sample)
set(HinnantDate_ROOT_DIR "/usr/local/lib/date")
include_directories(/usr/local/lib/date)
set(CMAKE_CXX_STANDARD 11)
if(UNIX)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/CMake)
set(SQLPP11_INCLUDE_DIR /usr/local/include)
find_package(Sqlpp11 REQUIRED)
add_executable(mysql_sample src/main.cpp)
include_directories(${sqlpp11_INCLUDE_DIRS})
include_directories(${sqlpp11-connector-mysql_INCLUDE_DIRS})
target_link_libraries(mysql_sample ${sqlpp11_LIBRARIES})
target_link_libraries(mysql_sample ${sqlpp11-connector-mysql_LIBRARIES})
target_link_libraries(mysql_sample mysqlclient)
include_directories(${PROJECT_SOURCE_DIR}/include)
add_subdirectory(include)
add_subdirectory(src)
add_subdirectory(test)
FindSqlpp11-connector-mysql.cmake
## -----------------------------------------------------------------------------
## Check for the library
find_library (sqlpp11-connector-mysql-mysql_LIBRARIES sqlpp11-connector-mysql-mysql
PATHS usr/local/cmake /usr/local/cmake/sqlpp11-connector-mysql-mysql /usr/local/lib /usr/lib /lib /sw/lib /usr/local/include
)
## -----------------------------------------------------------------------------
## Actions taken when all components have been found
if (sqlpp11-connector-mysql-mysql_INCLUDES AND sqlpp11-connector-mysql-mysql_LIBRARIES)
set (HAVE_sqlpp11-connector-mysql-mysql TRUE)
else (sqlpp11-connector-mysql-mysql_INCLUDES AND sqlpp11-connector-mysql-mysql_LIBRARIES)
if (NOT sqlpp11-connector-mysql-mysql_FIND_QUIETLY)
if (NOT sqlpp11-connector-mysql-mysql_INCLUDES)
message (STATUS "Unable to find sqlpp11-connector-mysql-mysql header files!")
endif (NOT sqlpp11-connector-mysql-mysql_INCLUDES)
if (NOT sqlpp11-connector-mysql-mysql_LIBRARIES)
message (STATUS "Unable to find sqlpp11-connector-mysql-mysql library files!")
endif (NOT sqlpp11-connector-mysql-mysql_LIBRARIES)
endif (NOT sqlpp11-connector-mysql-mysql_FIND_QUIETLY)
endif (sqlpp11-connector-mysql-mysql_INCLUDES AND sqlpp11-connector-mysql-mysql_LIBRARIES)
if (HAVE_sqlpp11-connector-mysql-mysql)
if (NOT sqlpp11-connector-mysql-mysql_FIND_QUIETLY)
message (STATUS "Found components for sqlpp11-connector-mysql-mysql")
message (STATUS "sqlpp11-connector-mysql-mysql_INCLUDES = ${sqlpp11-connector-mysql-mysql_INCLUDES}")
message (STATUS "sqlpp11-connector-mysql-mysql_LIBRARIES = ${sqlpp11-connector-mysql-mysql_LIBRARIES}")
endif (NOT sqlpp11-connector-mysql-mysql_FIND_QUIETLY)
else (HAVE_sqlpp11-connector-mysql-mysql)
if (sqlpp11-connector-mysql-mysql_FIND_REQUIRED)
message (FATAL_ERROR "Could not find sqlpp11-connector-mysql-mysql!")
endif (sqlpp11-connector-mysql-mysql_FIND_REQUIRED)
endif (HAVE_sqlpp11-connector-mysql-mysql)
mark_as_advanced (
HAVE_sqlpp11-connector-mysql-mysql
sqlpp11-connector-mysql-mysql_LIBRARIES
sqlpp11-connector-mysql-mysql_INCLUDES
)
and the error output:
root#beaglebone:~/cpp_work/sql_sample_project/build# cmake ..
-- Attempting to find SQLPP11 FILES
-- Unable to find SQLPP11 library files!
-- Unable to find sqlpp11-connector-mysql-mysql header files!
-- Unable to find sqlpp11-connector-mysql-mysql library files!
-- Configuring done
-- Generating done
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)