Xcode link with glew error - c++

I'm trying to write a project using OpenGL 4.1. I usually switch between Windows and OS X. On Windows I use Visual Studio 2013 making the project using cmake. This works just fine. On OS X, when I use cmake with -G "Unix Makefiles" I can compile and run just fine. However, if i generate an Xcode project, Xcode fails building with the error:
ld: library not found for -lglew
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I'm using this CMakeLists.txt.
cmake_minimum_required(VERSION 2.8.9)
project(Framework)
set(SRC_FILES src/shader.cpp
src/framework.cpp
src/fileio.cpp
src/scene.cpp
src/renderable.cpp
src/camera.cpp
src/mesh.cpp
src/material.cpp
src/light.cpp
src/triangle.cpp
src/cube.cpp
src/basicshader.cpp
src/frameworkmodel.cpp
src/texture.cpp
)
set(HEADER_FILES include/shader.h
include/framework.h
include/fileio.h
include/scene.h
include/renderable.h
include/camera.h
include/mesh.h
include/material.h
include/light.h
include/triangle.h
include/cube.h
include/basicshader.h
include/frameworkmodel.h
include/texture.h
)
if (WIN32)
list(APPEND SRC_FILES src/GLee.cpp src/glew.cpp)
list(APPEND HEADER_FILES include/GLee.h include/glew.h)
endif()
if (APPLE)
SET(GCC_COVERAGE_LINK_FLAGS "-framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo -lglew")
endif()
set(GLFW_PATH glfw-3.1)
set(SOIL_PATH SOIL)
add_subdirectory(${GLFW_PATH})
include_directories(${GLFW_PATH}/include)
include_directories(${SOIL_PATH})
file(GLOB SOIL_SRC
"${SOIL_PATH}/*.h"
"${SOIL_PATH}/*.c"
)
include_directories(./include)
add_library(soil ${SOIL_SRC})
add_library(framework ${SRC_FILES} ${HEADER_FILES})
target_link_libraries(framework soil)
add_executable(test01 tests/test01.cpp)
target_link_libraries(test01 framework)
target_link_libraries(test01 glfw ${GLFW_LIBRARIES})
target_link_libraries(test01 glfw ${OPENGL_glu_LIBRARY} ${GLFW_LIBRARIES})
target_link_libraries(test01 glfw ${GCC_COVERAGE_LINK_FLAGS})
Is there something obviously wrong with this?
SOLUTION
I found the .dylib location of my glew installation and added it to the xcode search path, works just as it should.

Related

Emscripten emcmake on win10, error when Including X11 support

I am working on a relatively simple c++ project, on windows 10.
Everything works fine when compiling to a Windows executable. But I have issues when trying to compile to Webassembly.
From Emscripten docs there, at least for windows, the procedure seems to be :
emcmake cmake .
# then
emmake make
but when I execute :
emcmake cmake .
I get this error:
configure: cmake .
-DCMAKE_TOOLCHAIN_FILE=C:\gui2one\CODE\emsdk\upstream\emscripten\cmake\Modules\Platform\Emscripten.cmake
-DCMAKE_CROSSCOMPILING_EMULATOR=C:/gui2one/CODE/emsdk/node/14.18.2_64bit/bin/node.exe;
--experimental-wasm-bulk-memory;--experimental-wasm-threads -G "MinGW Makefiles"
-- Including X11 support
CMake Error at C:/cmake-3.19.5-win64-x64/share/cmake-3.19/Modules/FindPackageHandleStandardArgs.cmake:218 (message):
Could NOT find X11 (missing: X11_X11_LIB)
Call Stack (most recent call first):
C:/cmake-3.19.5-win64-x64/share/cmake-3.19/Modules/FindPackageHandleStandardArgs.cmake:582 (_FPHSA_FAILURE_MESSAGE)
C:/cmake-3.19.5-win64-x64/share/cmake-3.19/Modules/FindX11.cmake:437 (find_package_handle_standard_args)
vendor/glfw/src/CMakeLists.txt:190 (find_package)
I tried to install libX11 using cygwin, but Cmake is still unable to find it.
I must say I feel lost in cross-compiling land ...
How can I make X11 available to Cmake ?
Here is the CmakeLists.txt for this project :
cmake_minimum_required(VERSION 3.2)
set (CMAKE_CXX_STANDARD 17)
project(Orbitals)
add_definitions(-DOGL_DEBUG)
include_directories(
cpp/
vendor/glad/include
cpp/Render
cpp/Objects
vendor/spdlog/include
vendor/glad/include
vendor/glad/include/glad
C:/gui2one/CODE/emsdk/upstream/emscripten/system/include
# ${EMSCRIPTEN_PATH}/upstream/emscripten/system/include/GLES3
)
set(RENDER_SRC
cpp/Render/Camera.cpp
cpp/Render/OpenGLBuffer.cpp
cpp/Render/OpenGLFrameBuffer.cpp
cpp/Render/OpenGLHDRSkybox.cpp
cpp/Render/OpenGLHDRTexture.cpp
cpp/Render/OpenGLShader.cpp
cpp/Render/OpenGLSkybox.cpp
cpp/Render/OpenGLTexture.cpp
cpp/Render/OpenGLVertexArray.cpp
)
add_executable(${PROJECT_NAME}
cpp/main.cpp
cpp/stb_image.cpp
cpp/Timer.cpp
cpp/pch.h
cpp/opengl_debug.h
cpp/Log.h
cpp/Log.cpp
cpp/RNDGenerator.cpp
cpp/Algorithms/PoissonDiscSampling.cpp
cpp/Mesh/Mesh.cpp
cpp/Mesh/MeshUtils.cpp
cpp/Mesh/MeshImporter.cpp
cpp/Mesh/PointCloud.cpp
cpp/Objects/Entity3d.cpp
cpp/Objects/LightObject.cpp
cpp/Objects/MeshObject.cpp
${RENDER_SRC}
)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 17)
target_include_directories(${PROJECT_NAME} PUBLIC
vendor/glfw/include
vendor/glad/include
vendor/glm
vendor/spdlog/include
vendor/
cpp/Render
C:/gui2one/CODE/emsdk/upstream/emscripten/system/include
)
# GLFW
add_subdirectory(vendor/glfw)
include_directories(vendor/glfw/include)
target_link_libraries(${PROJECT_NAME} glfw ${GLFW_LIBRARIES})
# GLAD
add_subdirectory(vendor/glad)
include_directories(vendor/glad/include)
target_link_libraries(${PROJECT_NAME} glad ${GLAD_LIBRARIES})
# ASSIMP
add_subdirectory(vendor/assimp)
include_directories(vendor/assimp/include)
target_link_libraries(${PROJECT_NAME} assimp ${ASSIMP_LIBRARIES})
You do not need to include glfw directory when compiling with emscripten. GLFW3 is already included in the emscripten library, so you do not need to compile it. You can simply omit add_subdirectory when building for HTML5 like so:
# GLFW
if (NOT EMSCRIPTEN)
add_subdirectory(vendor/glfw)
endif()
include_directories(vendor/glfw/include)
target_link_libraries(${PROJECT_NAME} glfw ${GLFW_LIBRARIES})
Also make sure you add USE_GLFW=3 link flag for the target you want to compile:
set_target_properties(target
PROPERTIES SUFFIX ".html"
LINK_FLAGS " --bind -s WASM=0 -s MIN_WEBGL_VERSION=1 -s ABORT_ON_WASM_EXCEPTIONS=1 -g2 -s USE_GLFW=3")

Project compiling with raylib static library

I am trying to create a game with the Raylib library. I just was until now just trying around inside the main.cpp and always compiled my code with this line inside the terminal.
clang -std=c++11 -framework CoreVideo -framework IOKit -framework Cocoa -framework GLUT -framework OpenGL libraylib.a main.cpp -o my_app
Now I want to recreate the Snake game just for fun. I thought I would be wise the spilt the main.cpp into multiple src files but I actually don't know how I should compile all of this. I tried to create a CMakeList.txt like this:
cmake_minimum_required (VERSION 3.0)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -framework CoreVideo")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -framework IOKit")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -framework Cocoa")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -framework GLUT")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -framework OpenGL")
project(Snake)
add_executable(
Snake
main.cpp
Snake.cpp
)
target_link_libraries(main ${CMAKE_SOURCE_DIR}/librarylib.a)
but this doesn't work. This is the Error message.
CMake Error at CMakeLists.txt:18 (target_link_libraries):
Cannot specify link libraries for target "main" which is not built by this
project.
-- Configuring incomplete, errors occurred!
Are there better ways to compile this project and can anyone explain to me what the -framework flag actually does? I still want to use VSCode because I want to learn how to use the terminal a bit better.
Edit: Information form brew ls --verbose raylib:
/usr/local/Cellar/raylib/2.5.0/LICENSE.md
/usr/local/Cellar/raylib/2.5.0/INSTALL_RECEIPT.json
/usr/local/Cellar/raylib/2.5.0/.brew/raylib.rb
/usr/local/Cellar/raylib/2.5.0/CHANGELOG
/usr/local/Cellar/raylib/2.5.0/include/raylib.h
/usr/local/Cellar/raylib/2.5.0/HISTORY.md
/usr/local/Cellar/raylib/2.5.0/README.md
/usr/local/Cellar/raylib/2.5.0/lib/pkgconfig/raylib.pc
/usr/local/Cellar/raylib/2.5.0/lib/cmake/raylib/raylib-config-version.cmake
/usr/local/Cellar/raylib/2.5.0/lib/cmake/raylib/raylib-config.cmake
/usr/local/Cellar/raylib/2.5.0/lib/libraylib.2.5.0.dylib
/usr/local/Cellar/raylib/2.5.0/lib/libraylib.2.dylib
/usr/local/Cellar/raylib/2.5.0/lib/libraylib.a
/usr/local/Cellar/raylib/2.5.0/lib/libraylib.dylib
Solved it by setting my CMakeLists.txt up like this:
cmake_minimum_required(VERSION 3.0)
project(Snake)
set (CMAKE_CXX_STANDARD 11)
# Executable & linking
add_executable(${PROJECT_NAME} main.cpp snake.cpp)
if (NOT TARGET raylib)
find_package(raylib 2.5.0 REQUIRED)
endif()
target_link_libraries(${PROJECT_NAME} raylib)
You want to link your executable to librarylib.a. The target name of your executable is Snake.
If we look at the error:
Cannot specify link libraries for target "main" which is not built by this project.
Indeed, you never added a library or an executable called main.
This is what should be in your target_link_libraries call should look like:
target_link_libraries(Snake PUBLIC "${CMAKE_SOURCE_DIR}/librarylib.a")

Getting SDL2 to work on Clion, Windows 10 using MinGW

I cannot for the life of me get SDL2 to work with my programming group's project.
I'm using
-Clion 1.2.1
-SDL 2.0.3
-MinGW 5.0
The compiler starts yelling at me from within the Graphics.h file which includes SDL like so:
#include <SDL.h>
#include <SDL_image.h>
with the error being:
fatal error: SDL.h: No such file or directory
compilation terminated.
I tried including with
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
which still yielded the same error.
I downloaded SDL from the MinGW 32/64-bit download of development libraries from: https://www.libsdl.org/download-2.0.php. I also linked the respective ..\SDL2\x86_64-w64-mingw32\include and lib to path in system->advanced system settings->...
Still nothing.
cmake_minimum_required(VERSION 3.3)
project(ClionProjects)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lsdl2")
set(SOURCE_FILES
Kod/Graphics/Graphics.cc
Kod/Graphics/Graphics.h
Kod/Game/Game.cc
Kod/Game/Game.h
Kod/Gameboard/Gameboard.cc
Kod/Gameboard/Gameboard.h
Kod/Meeple/Meeple.cc
Kod/Meeple/Meeple.h
Kod/Player/Player.cc
Kod/Player/Player.h
Kod/Resource/Resource.cc
Kod/Resource/Resource.h
Kod/Tile/Tile.cc
Kod/Tile/Tile.h
Kod/Carcassonne.cc)
add_executable(ClionProjects ${SOURCE_FILES} Kod/Carcassonne.cc)
target_link_libraries(ClionProjects SDL2main SDL2 SDL2_image)
is the cmakefile I have in Clion. I've been bashing my head bloody trying to get this to work and none of the previous Stackoverflow questions managed to solve my issue.
Personally I uses MSYS2 in my project. The MINGW64 vesion of SDL2 and the other library were installed, as well as the other toolchains like gcc, cmake, and pkg-config (toolchains are MINGW64 version as well).
Then I point my CLion toolchain configuration to the c:\msys2\mingw64, given that I install the msys2 at c:\msys2.
The FindPkgConfig CMake module is used to locate the SDL2 library and include files location.
Please find the example below (I also use FreeType2 and harfbuzz as well). The important part is the FindPkgConfig part (pkg_check_modules) and include/link part.
Make sure to reload the configuration after you have modified the cmake file.
cmake_minimum_required (VERSION 2.6)
project (pgengine)
# The version number.
set (Tutorial_VERSION_MAJOR 0)
set (Tutorial_VERSION_MINOR 1)
add_definitions(-std=c++11)
aux_source_directory(src SRC_LIST)
aux_source_directory(src/game SRC_LIST)
aux_source_directory(src/graphics SRC_LIST)
aux_source_directory(src/sound SRC_LIST)
aux_source_directory(src/system SRC_LIST)
aux_source_directory(src/visual_novel SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})
INCLUDE(FindPkgConfig)
pkg_check_modules(FREETYPE2 REQUIRED freetype2)
pkg_check_modules(HARFBUZZ REQUIRED harfbuzz)
pkg_check_modules(SDL2 REQUIRED sdl2)
pkg_check_modules(SDL2_IMAGE REQUIRED SDL2_image)
pkg_check_modules(SDL2_MIXER REQUIRED SDL2_mixer)
include_directories(${SDL2_INCLUDE_DIRS}
${SDL2_IMAGE_INCLUDE_DIRS}
${SDL2_MIXER_INCLUDE_DIRS}
${FREETYPE2_INCLUDE_DIRS}
${HARFBUZZ_INCLUDE_DIRS})
link_directories (${SDL2_LIBRARY_DIRS}
${SDL2_IMAGE_LIBRARY_DIRS}
${SDL2_MIXER_LIBRARY_DIRS}
${FREETYPE2_LIBRARY_DIRS}
${HARFBUZZ_LIBRARY_DIRS})
target_link_libraries (pgengine ${SDL2_LIBRARIES}
${SDL2_IMAGE_LIBRARIES}
${SDL2_MIXER_LIBRARIES}
${FREETYPE2_LIBRARIES}
${HARFBUZZ_LIBRARIES})
This has been tested on Windows (MSYS2) and Linux.

Use GLib in CLion

I trying to compile my test GLib project using CLion. So I added #include "glib-2.0/glib.h" in my cpp file and added include_directories(/usr/include/glib-2.0/glib) in my CMakeLists.txt. But got output in CLion:
fatal error: glib/galloca.h: No such file or directory
So how I can correctly use GLib in my project in CLion?
Here's the skeleton I use for glib on my Mac (glib2 and pkgconfig installed via MacPorts):
cmake_minimum_required(VERSION 3.1)
project(HelloGlib)
include(FindPkgConfig)
pkg_check_modules(GLIB glib-2.0 REQUIRED)
include_directories(${GLIB_INCLUDE_DIRS})
set(SOURCE_FILES main.c)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} ${GLIB_LIBRARIES})
The include directory is supposed to be /usr/include/glib-2.0 not /usr/include/glib-2.0/glib. Or, more portably, pkg-config --cflags glib-2.0.

Cmake link library target link error

Hi I have problem with linkg Glfw and other libraries using cmake.
From command line i compile like this
g++ main.cpp -lGL -lGLU -lGLEW -lglfw
But I wanted to use cmake for compiling. I tried to use target_linkg_libraries but this produce error
CMake Error at CMakeLists.txt:18 (target_link_libraries): Cannot
specify link libraries for target "GL" which is not built by this
project.
I tried do this using add definitions. I dont see error but this don't link libraries.
cmake_minimum_required (VERSION 2.6)
project (test)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
ADD_DEFINITIONS(
-lGL
-lGLU
-lGLEW
-lglfw
)
add_executable(test.out
main.cpp
)
target_link_libraries(GL GLU GLEW glfw)
The syntax for target_link_libraries is:
target_link_libraries(your_executable_name libraries_list)
And you don't have to add add_definition statements (target_link_libraries adds this options)
There are also some useful variables provided by OpenGL and GLEW packages.
Your CMakeLists.txt should be like:
cmake_minimum_required (VERSION 2.6)
project (test)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR} ${GLEW_INCLUDE_DIRS})
add_executable(test
main.cpp
)
target_link_libraries(test ${OPENGL_LIBRARIES} ${GLEW_LIBRARIES})
One important detail to keep in mind is to place the target_link_libraries after the add_executable (or add_library) line.