im trying to build and link OpenAL-Soft (https://github.com/kcat/openal-soft/tree/master) with CMake as an external project on CLion.
I get OpenAL source files via:
ExternalProject_Add(OpenAL-lib
GIT_REPOSITORY https://github.com/kcat/openal-soft.git
GIT_TAG makemhr
SOURCE_DIR ${PROJECT_BINARY_DIR}/downloaded_dependencies/OpenAL
BINARY_DIR ${PROJECT_BINARY_DIR}/builded_dependencies/OpenAL
INSTALL_DIR ${PROJECT_BINARY_DIR}/dependencies/OpenAL
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> -DLIBTYPE=SHARED
)
then i search the package with:
find_package (OpenAL PATHS "${PROJECT_BINARY_DIR}/dependencies/OpenAL" NO_DEFAULT_PATH CONFIG REQUIRED)
find_package(OpenAL CONFIG REQUIRED)
and finally link to my executable:
add_executable(Nite main.cpp)
target_link_libraries(Nite PUBLIC OpenAL)
First of all i download, build and install OpenAL without the find_package() and target_link_libraries() commands, then add them and build the entire project, at this point at get the following error:
FAILED: Nite.exe
C:\Windows\system32\cmd.exe /C "cd . && "C:\Users\Galo\AppData\Local\Programs\CLion Nova\bin\cmake\win\x64\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\Nite.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\x86\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\x86\mt.exe --manifests -- "E:\Visual Studio\Community\VC\Tools\MSVC\14.38.33130\bin\Hostx86\x86\link.exe" /nologo CMakeFiles\Nite.dir\main.cpp.obj /out:Nite.exe /implib:Nite.lib /pdb:Nite.pdb /version:0.0 /machine:X86 /INCREMENTAL:NO /subsystem:console dependencies\glfw\lib\glfw3dll.lib dependencies\glm\lib\glm.lib E:\VulkanSDK\Lib32\vulkan-1.lib OpenAL.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
LINK: command "E:\Visual Studio\Community\VC\Tools\MSVC\14.38.33130\bin\Hostx86\x86\link.exe /nologo CMakeFiles\Nite.dir\main.cpp.obj /out:Nite.exe /implib:Nite.lib /pdb:Nite.pdb /version:0.0 /machine:X86 /INCREMENTAL:NO /subsystem:console dependencies\glfw\lib\glfw3dll.lib dependencies\glm\lib\glm.lib E:\VulkanSDK\Lib32\vulkan-1.lib OpenAL.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST:EMBED,ID=1" failed (exit code 1181) with the following output:
LINK : fatal error LNK1181: no se puede abrir el archivo de entrada 'OpenAL.lib'
When i build and intall OpenAL i get an OpenAL32.dll, if i change the LIBTYPE option to STATIC i get an OpenAL32.lib
Well, i solved it, when linking the library to the executable the target should be OpenAL::OpenAL instead of only OpenAL. I mean:
right way: target_link_libraries(Nite PUBLIC OpenAL::OpenAL)
wrong way: target_link_libraries(Nite PUBLIC OpenAL)