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})
Related
I am compiling a C++ Program.
When I compile it on my machine the program runs just fine.
When I zip the whole build and send it over to friend he gets the following error:
error while loading shared libraries: libCommon.so: cannot open shared object file: No such file or directory
Somehow I believe that the shared library is not properly linked.
Here is my main CMakeLists.txt:
cmake_minimum_required(VERSION 3.16)
project(Vibranium_Core)
#set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_STANDARD 17)
set(FLATBUFFERS_MAX_PARSING_DEPTH 16)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_INSTALL_RPATH "$ORIGIN")
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
if(APPLE)
set(OPENSSL_INCLUDE_DIR "/opt/homebrew/opt/openssl#1.1/include")
endif()
if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
execute_process(
COMMAND git rev-list --count HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git --no-pager log -1 --format=%ai
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_RELEASED_ON
OUTPUT_STRIP_TRAILING_WHITESPACE
)
else(EXISTS "${CMAKE_SOURCE_DIR}/.git")
set(GIT_BRANCH "")
set(GIT_COMMIT_HASH "")
endif(EXISTS "${CMAKE_SOURCE_DIR}/.git")
message(STATUS "VibraniumCore current branch: ${GIT_BRANCH}")
message(STATUS "VibraniumCore Version: ${GIT_VERSION}")
message(STATUS "VibraniumCore commit hash: ${GIT_COMMIT_HASH}")
message(STATUS "Released on: ${GIT_RELEASED_ON}")
message(STATUS "Generating version.h")
configure_file(
${CMAKE_SOURCE_DIR}/cmake/version.h.in
${CMAKE_SOURCE_DIR}/Source/Common/Version.h
)
add_definitions(-DGIT_COMMIT_HASH="${GIT_COMMIT_HASH}")
add_definitions(-DGIT_BRANCH="${GIT_BRANCH}")
add_definitions(-DGIT_VERSION="${GIT_VERSION}")
add_definitions(-DGIT_RELEASED_ON="${GIT_RELEASED_ON}")
if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
message(STATUS "Target is 64 bits")
if (WIN32)
set(WINXXBITS Win64)
endif(WIN32)
else("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
message(STATUS "Target is 32 bits")
if (WIN32)
set(WINXXBITS Win32)
endif(WIN32)
endif("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
# set macro-directory
list(APPEND CMAKE_MODULE_PATH
"${CMAKE_SOURCE_DIR}/cmake/macros")
find_package(CURL REQUIRED)
find_package(MySQL REQUIRED)
find_package(Flatbuffers REQUIRED
PATHS /usr/local/flatbuffers)
find_package(Protobuf REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(gRPC CONFIG REQUIRED)
include_directories(${MYSQL_INCLUDE_DIR})
if(APPLE)
include_directories(/opt/homebrew/include)
include_directories(/usr/local/include)
endif()
# set default buildoptions and print them
include(cmake/options.cmake)
# Find revision ID and hash of the sourcetree
include(cmake/genrev.cmake)
# print out the results before continuing
include(cmake/showoptions.cmake)
# add dependencies
add_subdirectory(dep)
# add libraries and projects
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Source/Common)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Source/WorldServer)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Source/AuthServer)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Source/ClientEmulator)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Source/GameServerClientEmulator)
add_subdirectory(Tests)
set_target_properties(VibraniumCoreTests PROPERTIES EXCLUDE_FROM_ALL TRUE)
set_target_properties(gtest PROPERTIES EXCLUDE_FROM_ALL TRUE)
set_target_properties(gmock PROPERTIES EXCLUDE_FROM_ALL TRUE)
set_target_properties(gtest_main PROPERTIES EXCLUDE_FROM_ALL TRUE)
set_target_properties(gmock_main PROPERTIES EXCLUDE_FROM_ALL TRUE)
set_target_properties(
Common WorldServer AuthServer ClientEmulator
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
Any idea why I get this error and how can I fix it?
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.
I have difficulties with CMakeLists file. I have done pretty much the same in my other project, so i know the paths are correct. But i tried to make it a bit more pretty so I created a new CMakeLists file.
Now my project fails to find the headers.
Anyone see what I have missed?
Here is my CMakeLists file:
project("Test Cell Camera")
set(VERSION_MAJOR 0)
set(VERSION_MINOR 1)
set(VERSION_PATCH 0)
set(CMAKE_CXX_STANDARD 17)
set(lib_TARGET tcc)
set(exec_TARGET tcc_exe)
set(test_TARGET tcc_test)
set(SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
set(INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
set(TESTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests")
set(LIBS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/libs")
set(CONFIG_DIR "${CMAKE_CURRENT_SOURCE_DIR}/config")
set(main_SRC_FILE "${SRC_DIR}/main.cpp")
include_directories(
${SRC_DIR}
${INCLUDE_DIR}
"C:/Program Files/Basler/pylon 5/Development/include" # Basler
)
file(GLOB lib_INCLUDE "${INCLUDE_DIR}/*/*.h")
file(GLOB lib_SRC "${SRC_DIR}/*.cpp")
list(FILTER lib_SRC EXCLUDE REGEX ${main_SRC_FILE})
file(GLOB main_SRC ${main_SRC_FILE})
# Add all test sources
file(GLOB test_SRC "${TESTS_DIR}/*.cpp")
# Documentation doxifile path
set(lib_DOC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/doc/")
link_directories("C:/Program Files/Basler/pylon 5/Development/lib/x64")
set(OpenCV_DIR "C:/OpenCV/3.4.7")
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
set(lib_dep_LIBS PylonC.lib ${OpenCV_LIBS})
add_library(${lib_TARGET} ${lib_SRC})
target_link_libraries(${lib_TARGET} ${lib_dep_LIBS})```
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 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})