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?
Given the project structure
src
MyModule.cpp
test
TestMyModule.cpp
How does one import MyModule in TestMyModule.cpp?
Edit: apparently a environment issue is making me unable to import it
My CMakeList.txt:
cmake_minimum_required (VERSION 3.8)
if (CMAKE_VERSION VERSION_GREATER 3.12)
set_property(TARGET FocusApp PROPERTY CXX_STANDARD 20)
endif()
project ("App")
enable_testing()
add_executable (App "src/EntryPoint.ixx" "src/Time.ixx" )
add_executable(TestTime "src/Time.ixx" "test/TestTime.ixx" )
if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR MYPROJECT_BUILD_TESTING) AND BUILD_TESTING)
add_subdirectory(test)
endif()
add_test("testerino" TestTime.exe)
The env is VTK-8.0 ITK-5.2 QT-5.12
This error occurs when I compile this cmake file:
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
project(QtDICOMViewer)
find_package(VTK REQUIRED)
#find_package(VTK COMPONENTS
# vtkCommonCore
# vtkFiltersSources
# vtkGUISupportQt
# vtkIOImage
# vtkInteractionImage
# vtkFiltersCore
# vtkInfovisCore
# vtkInteractionStyle
# vtkViewsQt
# vtkCommonDataModel
# vtkCommonExecutionModel
# vtkRenderingCore
# vtkRenderingFreeType
# vtkRenderingOpenGL2
# )
include(${VTK_USE_FILE})
if("${VTK_QT_VERSION}" STREQUAL "")
message(FATAL_ERROR "VTK was not built with Qt")
endif()
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
include_directories(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)
# Set your files and resources here
set( Srcs main.cpp mainwindow.cpp)
set( Hdrs mainwindow.h )
set( MOC_Hdrs mainwindow.h )
set( UIs mainwindow.ui )
set( QRCs images.qrc )
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
find_package(Qt5 COMPONENTS Widgets REQUIRED QUIET)
qt5_wrap_ui(UI_Srcs ${UIs})
qt5_add_resources(QRC_Srcs ${QRCs} )
source_group("Resources" FILES
${UIs}
${QRCs}
${EXE_ICON} # Not present
)
source_group("Generated" FILES
${UI_Srcs}
${MOC_Srcs}
${QRC_Srcs}
)
include_directories(/usr/include/gdcm-2.6)
# CMAKE_AUTOMOC in ON so the MocHdrs will be automatically wrapped.
add_executable(QtDICOMViewer MACOSX_BUNDLE ${Srcs} ${Hdrs} ${UI_Srcs} ${MOC_Hdrs} ${QRC_Srcs})
qt5_use_modules(QtDICOMViewer Core Gui Widgets)
target_link_libraries(QtDICOMViewer ${VTK_LIBRARIES} ${ITK_LIBRARIES})
And the error is:
undefined reference to 'QVTKWidget::QVTKWidget' in ui.mainwindow.h:xxx
There is no LINK errors and any include fault, just can't detect this variable. I'm struggling in it all day:( But when I compile the example in VTK/Examples, nothing fails. The example CMakeLists is:
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
project(QtVTKRenderWindows)
find_package(VTK COMPONENTS
vtkCommonCore
vtkFiltersSources
vtkGUISupportQt
vtkIOImage
vtkInteractionImage
vtkFiltersCore
vtkInfovisCore
vtkInteractionStyle
vtkViewsQt
)
include(${VTK_USE_FILE})
if("${VTK_QT_VERSION}" STREQUAL "")
message(FATAL_ERROR "VTK was not built with Qt")
endif()
include_directories(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)
# Set your files and resources here
set( Srcs QtVTKRenderWindowsApp.cxx QtVTKRenderWindows.cxx)
set( Hdrs QtVTKRenderWindows.h)
set( MOC_Hdrs QtVTKRenderWindows.h)
#set( UIs QtVTKRenderWindows.ui )
set( QRCs Icons/icons.qrc )
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
find_package(Qt5 COMPONENTS Widgets REQUIRED QUIET)
#qt5_wrap_ui(UI_Srcs ${UIs})
qt5_add_resources(QRC_Srcs ${QRCs} )
source_group("Resources" FILES
${UIs}
${QRCs}
${EXE_ICON} # Not present
)
source_group("Generated" FILES
${UI_Srcs}
${MOC_Srcs}
${QRC_Srcs}
)
# CMAKE_AUTOMOC in ON so the MocHdrs will be automatically wrapped.
add_executable(QtVTKRenderWindows MACOSX_BUNDLE ${Srcs} ${Hdrs} ${UI_Srcs} ${MOC_Hdrs} ${QRC_Srcs})
qt5_use_modules(QtVTKRenderWindows Core Gui Widgets)
target_link_libraries(QtVTKRenderWindows ${VTK_LIBRARIES})
I can't find there is any difference between them. So is there any probability that the code resulting in this error?
You have to link your program to the library vtkGUISupportQt-7.1
In my case, I am in ubuntu 20.04 and that library is located in /usr/lib/x86_64-linux-gnu/libvtkGUISupportQt-7.1.so
you can get it installing the apt package: libvtk7-qt-dev
apt-get install libvtk7-qt-dev
This is the function that gives me a segmentation fault dump,
it's the line:
optimizedImage = SDL_DisplayFormat( loadedImage );
Trying to build this on ubuntu Linux using codeblocks for my IDE.
I'm very close and want to use SDL mixers capability and png would be nice to have fully set up as well.
Just discovered the function may be deprecated. SDL_ConvertSurfaceFormat(); seems to be the replacement and is part of sdl2.. But i get an undefined error when I try it.. sdl and sdl2 appear to be linked properly.
SDL_Surface *load_image( std::string filename )
{
//The image that's loaded
cout<< "entered load image files"<< endl;
SDL_Surface* loadedImage = NULL;
//The optimized surface that will be used
SDL_Surface* optimizedImage = NULL;
//Load the image
loadedImage = IMG_Load( filename.c_str() );
cout<< "image image should be set"<< endl;
//If the image loaded
if( loadedImage != NULL )
{
cout<< "loaded image isn't null, hooray!"<< endl;
//Create an optimized surface
optimizedImage = SDL_DisplayFormat( loadedImage );
cout<< "optimized image should be in display format now"<< endl;
//Free the old surface
SDL_FreeSurface( loadedImage );
cout<< "sdl surface is free"<< endl;
//If the surface was optimized
if( optimizedImage != NULL )
{cout<< "optimized image is not null"<< endl;
//Color key surface
SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, SDL_MapRGB( optimizedImage->format, 0, 0xFF, 0xFF ) );
cout<< "sdl setcolor key is ok"<< endl;
}
}
//Return the optimized surface
return optimizedImage;
}
Heres my cmakelists.text file
# CMake entry point
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(PNG REQUIRED)
find_package(ZLIB)
find_package(OpenGL REQUIRED)
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
add_definitions(${PNG_DEFINITIONS})
include_directories(${SDL2_INCLUDE_DIRS}
${SDL2_IMAGE_INCLUDE_DIRS})
include_directories(${PNG_INCLUDE_DIR})
find_path(PNG_INCLUDE_DIR png.h)
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
external/zlib-1.2.11/zlib.h
external/libpng-1.6.37/png.h
)
find_package(ZLIB)
if (ZLIB_FOUND)
include_directories(external/zlib-1.2.11)
#target_link_libraries(loaders ${ZLIB_LIBRARIES})
endif()
if (!PNG_FOUND)
message(STATUS "PNG not FOUND Don't use it")
endif()
if(!ZLIB_FOUND)
message(STATUS "ZLIB not FOUND")
endif()
include_directories(ZLIB external/zlib-1.2.11)
include_directories(PNG_INCLUDE_DIRS external/libpng-1.6.37)
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_directories(/usr/include)
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)
link_directories(/usr/include)
link_directories(external/libpng-1.6.37)
link_directories(ZLIB external/zlib-1.2.11)
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
)
target_link_libraries(loaders
-lSDLmain)
target_link_libraries(loaders
-lSDL)
target_link_libraries(loaders
-lSDL2_ttf)
target_link_libraries(loaders ${ZLIB_LIBRARIES})
target_link_libraries(loaders
-lSDL2_mixer)
target_link_libraries(loaders -zlib)
target_link_libraries(loaders ${PNG_LIBRARIES})
set_target_properties(loaders
PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(loaders ${SDL2_LIBRARIES} ${SDL2_IMAGE_LIBRARIES})
target_link_libraries(mageengine
${ALL_LIBS}
ANTTWEAKBAR_116_OGLCORE_GLFW
${SDL2_LIBRARIES}
loaders
)
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" )
i expect my program to not crash so I can further implement and debug code.
here's the output, repleat with cute but useful messages.
aaron#Zog:~/Desktop/maficengine/Mafic$ ./mageengine
LoadTexture object got constructed in mageengine from loadtexture.cpp
Reading image ./paint.bmp
Compiling shader : StandardShading.vertexshader
Compiling shader : StandardShading.fragmentshader
Linking program
Loading OBJ file plane.obj...
loadtexture() function works, inboundtexture is 1
ERROR(AntTweakBar) >> Parsing error in def string: Unknown attribute [true ...]
Compiling shader : StandardShading.vertexshader
Compiling shader : StandardShading.fragmentshader
Linking program
Loading OBJ file plane.obj...
passed sdl init everything
passed sdl init
entered load files
likely opened file background.png
entered load image files
image image should be set
loaded image isn't null, hooray!
Segmentation fault (core dumped)
the updated cmakelists.text after cleaning as advised in the comments below
# CMake entry point
cmake_minimum_required (VERSION 3.0)
project (maficengine LANGUAGES C CXX ASM)
set(CMAKE_MODULE_PATH "/home/aaron/Desktop/maficengine/cmake/")
find_package(PNG REQUIRED)
find_package(ZLIB REQUIRED)
find_package(OpenGL REQUIRED)
find_package(SDL2 REQUIRED)
find_package(SDL_image REQUIRED)# maybe sdl2_image
find_package(SDL_mixer REQUIRED)
#set(CMAKE_MODULE_PATH "/home/aaron/Desktop/maficengine/cmake/")
#et(SDL2_mixer_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
add_definitions(${PNG_DEFINITIONS})
include_directories(
${PNG_INCLUDE_DIRS}
${SDL2_INCLUDE_DIRS}
${SDL_MIXER_INCLUDE_DIR}
${SDL2_TTF_INCLUDE_DIRS}
${SDL_IMAGE_INCLUDE_DIRS}
${SDL2_IMAGE_INCLUDE_DIR}
)
file(GLOB_RECURSE SOURCE_FILES/usr/lib/x86_64-linux-gnu
${CMAKE_SOURCE_DIR}/src/*.c
${CMAKE_SOURCE_DIR}/src/*.cpp)
#include(FindSDL)
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()
#add_library(loaders
#external/myCustomHeaders/include/loadTexture.h
#external/myCustomHeaders/loadTexture.cpp
#)
if (ZLIB_FOUND)
include_directories(external/zlib-1.2.11)
message(STATUS "ZLIB FOUND")
elseif (!ZLIB_FOUND)
message(STATUS "Zlib not FOUND!")
endif()
if (PNG_FOUND)
message(STATUS "PNG FOUND ")
elseif (!PNG_FOUND)
message(STATUS "PNG not FOUND! ")
endif()
#if(SDL_FOUND)
# message(STATUS "sdl LIB FOUND!")
#elseif(!SDL_FOUND)
# message(STATUS "sdl LIB not FOUND!")
#endif()
if(SDL2_FOUND)
message(STATUS "sdl2 FOUND")
elseif(!SDL2_FOUND)
message(STATUS "sdl2 not FOUND!")
endif()
if(SDL_MIXER_FOUND)
message(STATUS "sdl mixer FOUND")
elseif(!SDL_MIXER_FOUND)
message(STATUS "sdl mixer not FOUND!")
endif()
if(SDL_IMAGE_FOUND)
message(STATUS "sdl image FOUND")
elseif(!SDL_IMAGE_FOUND)
message(STATUS "sdl image not FOUND!")
endif()
include_directories( external/myCustomHeaders/include )
include_directories(/usr/include)
include(FindPackageHandleStandardArgs)
#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)
link_directories(/usr/include)
link_directories(external/libpng-1.6.37)
link_directories(ZLIB external/zlib-1.2.11)
add_subdirectory (external)
# On Visual 2005 and above, this module can set the debug working directory
cmake_policy(SET CMP0026 OLD)
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
${SDL2_LIBRARIES}
${SDL2_IMAGE_LIBRARIES}
${SDL2_MIXER_LIBRARIES}
${SDL2_TTF_LIBRARIES}
)
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
)
target_link_libraries(mageengine
-lSDLmain)
target_link_libraries(mageengine
-lSDL)
# target_link_libraries(loaders
# -lSDL2_ttf)
#target_link_libraries(loaders ${ZLIB_LIBRARIES})
target_link_libraries(mageengine
-lSDL2_mixer)
#(loaders -zlib)
#target_link_libraries(loaders ${PNG_LIBRARIES})
set_target_properties(mageengine
PROPERTIES LINKER_LANGUAGE CXX)
#target_link_libraries(loaders ${SDL2_LIBRARIES} ${SDL2_IMAGE_LIBRARIES})
target_link_libraries(mageengine
${ALL_LIBS}
ANTTWEAKBAR_116_OGLCORE_GLFW
)
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/"
)
elseif (${CMAKE_GENERATOR} MATCHES "Xcode" )
endif (NOT ${CMAKE_GENERATOR} MATCHES "Xcode" )
Finally...tried SDL sound libraries for my game-engine again .... and found a way through!!!, good sound ...clear as a bell now, but i still think I will have to add sdl_mixer libraries to be satisfied. But this time I think I can do it. I found an old blog that sent me in the right direction. i think I installed SDL then upgraded to dev libraries, but it's the wrong order, then I couldn't purge the old library properly, but dug deeper and added tools to trace and destroy and finesse files and symbols till.. magic happened.. totally incredibly hard to do. Here's the blog that sent me the right way->
"If you built your own SDL, you probably didn't have development headers
for PulseAudio (or ALSA), so it's trying to use /dev/dsp, which doesn't
exist on many modern Linux systems (hence, SDL_Init(SDL_INIT_AUDIO)
succeeds, but no devices are found when you try to open one). "apt-get
install libasound2-dev libpulse-dev" and rebuild SDL...let the configure
script find the new headers so it includes PulseAudio and ALSA support. "
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