Dan Quinn
Dan Quinn

Reputation: 41

Including SOIL2 library in a CMake project

I'm trying to include SOIL2 in my C++ OpenGL project.

So far I've

Platform is MacOS (Catalina) I'm still new to CMake, so I'm pretty sure that's where my problem is.

At the moment, my CMakeLists file looks like this:

cmake_minimum_required(VERSION 3.8)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD 99)
set(This ComputerGraphicsProgramming)
project(${This} CXX C)

file(GLOB_RECURSE SOURCES src/*.cpp)
file(GLOB_RECURSE SOIL2_SOURCES /usr/local/include/SOIL2/*.c)
add_executable(${This} ${SOURCES} ${HEADERS})

include_directories(
  include
  lib
  /usr/local/include
)
link_directories(
  /usr/local/include
  /usr/local/include/SOIL2
)

find_package(OpenGL REQUIRED)
find_package(glfw3 REQUIRED)
find_package(glew REQUIRED)
find_package(glm REQUIRED)
find_library(soil2-debug REQUIRED)

target_link_libraries(${This}
  GLEW::GLEW
  ${OPENGL_LIBRARIES} glfw
  soil2-debug
)

Texture.hpp, the file where I'm including SOIL, looks like this:

#include <GL/glew.h>
#include <SOIL2/SOIL2.h>
#include <string>

class Texture
{
  public:
    Texture(std::string filename);
    ~Texture();

  private:
    unsigned int m_ID;
};

And these are my errors when I run make:

$ make
[  9%] Linking CXX executable ComputerGraphicsProgramming
ld: library not found for -lsoil2-debug
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [ComputerGraphicsProgramming] Error 1
make[1]: *** [CMakeFiles/ComputerGraphicsProgramming.dir/all] Error 2
make: *** [all] Error 2

Any help appreciated!

Upvotes: 2

Views: 2267

Answers (2)

Dan Quinn
Dan Quinn

Reputation: 41

Finally got project to build, using the following CMakeLists file. Thanks for the replies!

cmake_minimum_required(VERSION 3.8)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD 99)
set(This ComputerGraphicsProgramming)

project(${This} CXX C)

file(GLOB_RECURSE SOURCES src/*.cpp)
add_executable(${This} ${SOURCES} ${HEADERS})

include_directories(
  include
  /usr/local/include
)

find_package(OpenGL REQUIRED)
find_package(glfw3 REQUIRED)
find_package(glew REQUIRED)
find_package(glm REQUIRED)
find_library(SOIL2 soil2-debug)

target_link_libraries(${This}
  GLEW::GLEW
  ${OPENGL_LIBRARIES} glfw
  ${SOIL2}
)

Upvotes: 2

dboy
dboy

Reputation: 1057

looks like the libsoil2-debug.a couldn't be found. Try to add /usr/local/lib into your CMAKE_PREFIX_PATH:

list(APPEND CMAKE_PREFIX_PATH "/usr/local/lib")

somewhere on the top of your CMakeList.txt file

Upvotes: 1

Related Questions