1

I have the following CMakeLists.txt, trying to build my software on Windows with MinGW-w64:

#
# Initial CMake and project setup
#

# Required CMake version (ExternalProject)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
INCLUDE(ExternalProject)
SET(PROJECT_NAME Khronos)
PROJECT(${PROJECT_NAME})

# Set software version
SET(APPLICATION_VERSION_MAJOR "0")
SET(APPLICATION_VERSION_MINOR "4")
SET(APPLICATION_VERSION_PATCH "0")
SET(APPLICATION_VERSION "${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINOR}.${APPLICATION_VERSION_PATCH}")

SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
SET_DIRECTORY_PROPERTIES(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/library-build)

#
# Setup compiler flags
#

if (NOT CMAKE_BUILD_TYPE)
    message(STATUS "No build type selected, default to Release")
    set(CMAKE_BUILD_TYPE Release FORCE)
endif()

set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -std=gnu11 -O0 -fprofile-arcs -ftest-coverage")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -std=gnu11 -O3")

if (GCC_VERSION VERSION_GREATER "4.8")
elsif (GCC_VERSION VERSION_GREATER "4.1.2")
    SET (GCC_COMMON_WARNING_FLAGS "-pedantic -Wall -Wextra -Wconversion -Wfloat-equal -Wformat=2 -Winit-self -Winline -Winvalid-pch -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wstack-protector -Wstrict-null-sentinel -Wswitch-default -Wswitch-enum")
    SET (GCC_COMMON_WARNING_FLAGS "${GCC_COMMON_WARNING_FLAGS} -Wno-unused-parameter")
    SET (GCC_CXX_WARNING_FLAGS "-Wctor-dtor-privacy")
else ()
    SET(GCC_COMMON_WARNING_FLAGS "-pedantic -Wall -Wextra -Wconversion -Wfloat-equal -Wformat=2 -Winit-self -Winline -Winvalid-pch -Wmissing-include-dirs -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wstack-protector -Wstrict-null-sentinel -Wswitch-default -Wswitch-enum")
    SET(GCC_COMMON_WARNING_FLAGS "${GCC_COMMON_WARNING_FLAGS} -Wno-unused-parameter")
    SET(GCC_CXX_WARNING_FLAGS "-Wctor-dtor-privacy")
endif ()

#
# Find Doxygen for documentation
#

# add a target to generate API documentation with Doxygen
FIND_PACKAGE(Doxygen)
if (DOXYGEN_FOUND)
    ADD_CUSTOM_TARGET(DOC
        ${DOXYGEN_EXECUTABLE} ${CMAKE_SOURCE_DIR}/Doxyfile
        WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src
        COMMENT "Generating API documentation with Doxygen" VERBATIM
        )
endif ()

#
# Find/install dependencies
#

IF(WIN32)
    INCLUDE(${CMAKE_MODULE_PATH}/Win32-ExternalProjects.txt)
ELSE(UNIX)
    INCLUDE(${CMAKE_MODULE_PATH}/Unix-ExternalProjects.txt)
ENDIF()

#
# Final project settings
#

INCLUDE_DIRECTORIES(include)
ADD_SUBDIRECTORY(src)

ADD_EXECUTABLE(${PROJECT_NAME}
        $<TARGET_OBJECTS:audio>
        $<TARGET_OBJECTS:util>
        $<TARGET_OBJECTS:main>
        )

TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${LIBS})

if (DEPENDENCIES)
    MESSAGE (STATUS "Any missing dependencies will be downloaded upon running \"make\"")
    ADD_DEPENDENCIES(${PROJECT_NAME} ${DEPENDENCIES})
endif ()

I'm able to compile everything, but I'm having trouble linking the executable to the libraries:

"C:\Program Files (x86)\CMake\bin\cmake.exe" -HC:\Users\syb0rg\Downloads\Khronos -BC:\Users\syb0rg\Downloads\Khronos\build --check-build-system CMakeFiles\Makefile.cmake 0
"C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_progress_start C:\Users\syb0rg\Downloads\Khronos\build\CMakeFiles C:\Users\syb0rg\Downloads\Khronos\build\CMakeFiles\progress.marks
make -f CMakeFiles\Makefile2 all
make[1]: Entering directory `C:/Users/syb0rg/Downloads/Khronos/build'
make -f CMakeFiles\sphinxbase.dir\build.make CMakeFiles/sphinxbase.dir/depend
make[2]: Entering directory `C:/Users/syb0rg/Downloads/Khronos/build'
"C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\syb0rg\Downloads\Khronos C:\Users\syb0rg\Downloads\Khronos C:\Users\syb0rg\Downloads\Khronos\build C:\Users\syb0rg\Downloads\Khronos\build C:\Users\syb0rg\Downloads\Khronos\build\CMakeFiles\sphinxbase.dir\DependInfo.cmake --color=
make[2]: Leaving directory `C:/Users/syb0rg/Downloads/Khronos/build'
make -f CMakeFiles\sphinxbase.dir\build.make CMakeFiles/sphinxbase.dir/build
make[2]: Entering directory `C:/Users/syb0rg/Downloads/Khronos/build'
make[2]: Nothing to be done for `CMakeFiles/sphinxbase.dir/build'.
make[2]: Leaving directory `C:/Users/syb0rg/Downloads/Khronos/build'
[ 17%] Built target sphinxbase
make -f CMakeFiles\LibSndFile.dir\build.make CMakeFiles/LibSndFile.dir/depend
make[2]: Entering directory `C:/Users/syb0rg/Downloads/Khronos/build'
"C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\syb0rg\Downloads\Khronos C:\Users\syb0rg\Downloads\Khronos C:\Users\syb0rg\Downloads\Khronos\build C:\Users\syb0rg\Downloads\Khronos\build C:\Users\syb0rg\Downloads\Khronos\build\CMakeFiles\LibSndFile.dir\DependInfo.cmake --color=
make[2]: Leaving directory `C:/Users/syb0rg/Downloads/Khronos/build'
make -f CMakeFiles\LibSndFile.dir\build.make CMakeFiles/LibSndFile.dir/build
make[2]: Entering directory `C:/Users/syb0rg/Downloads/Khronos/build'
make[2]: Nothing to be done for `CMakeFiles/LibSndFile.dir/build'.
make[2]: Leaving directory `C:/Users/syb0rg/Downloads/Khronos/build'
[ 35%] Built target LibSndFile
make -f CMakeFiles\pocketsphinx.dir\build.make CMakeFiles/pocketsphinx.dir/depend
make[2]: Entering directory `C:/Users/syb0rg/Downloads/Khronos/build'
"C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\syb0rg\Downloads\Khronos C:\Users\syb0rg\Downloads\Khronos C:\Users\syb0rg\Downloads\Khronos\build C:\Users\syb0rg\Downloads\Khronos\build C:\Users\syb0rg\Downloads\Khronos\build\CMakeFiles\pocketsphinx.dir\DependInfo.cmake --color=
make[2]: Leaving directory `C:/Users/syb0rg/Downloads/Khronos/build'
make -f CMakeFiles\pocketsphinx.dir\build.make CMakeFiles/pocketsphinx.dir/build
make[2]: Entering directory `C:/Users/syb0rg/Downloads/Khronos/build'
make[2]: Nothing to be done for `CMakeFiles/pocketsphinx.dir/build'.
make[2]: Leaving directory `C:/Users/syb0rg/Downloads/Khronos/build'
[ 53%] Built target pocketsphinx
make -f CMakeFiles\PortAudio.dir\build.make CMakeFiles/PortAudio.dir/depend
make[2]: Entering directory `C:/Users/syb0rg/Downloads/Khronos/build'
"C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\syb0rg\Downloads\Khronos C:\Users\syb0rg\Downloads\Khronos C:\Users\syb0rg\Downloads\Khronos\build C:\Users\syb0rg\Downloads\Khronos\build C:\Users\syb0rg\Downloads\Khronos\build\CMakeFiles\PortAudio.dir\DependInfo.cmake --color=
make[2]: Leaving directory `C:/Users/syb0rg/Downloads/Khronos/build'
make -f CMakeFiles\PortAudio.dir\build.make CMakeFiles/PortAudio.dir/build
make[2]: Entering directory `C:/Users/syb0rg/Downloads/Khronos/build'
make[2]: Nothing to be done for `CMakeFiles/PortAudio.dir/build'.
make[2]: Leaving directory `C:/Users/syb0rg/Downloads/Khronos/build'
[ 71%] Built target PortAudio
make -f src\audio\CMakeFiles\audio.dir\build.make src/audio/CMakeFiles/audio.dir/depend
make[2]: Entering directory `C:/Users/syb0rg/Downloads/Khronos/build'
"C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\syb0rg\Downloads\Khronos C:\Users\syb0rg\Downloads\Khronos\src\audio C:\Users\syb0rg\Downloads\Khronos\build C:\Users\syb0rg\Downloads\Khronos\build\src\audio C:\Users\syb0rg\Downloads\Khronos\build\src\audio\CMakeFiles\audio.dir\DependInfo.cmake --color=
make[2]: Leaving directory `C:/Users/syb0rg/Downloads/Khronos/build'
make -f src\audio\CMakeFiles\audio.dir\build.make src/audio/CMakeFiles/audio.dir/build
make[2]: Entering directory `C:/Users/syb0rg/Downloads/Khronos/build'
make[2]: Nothing to be done for `src/audio/CMakeFiles/audio.dir/build'.
make[2]: Leaving directory `C:/Users/syb0rg/Downloads/Khronos/build'
[ 73%] Built target audio
make -f src\util\CMakeFiles\util.dir\build.make src/util/CMakeFiles/util.dir/depend
make[2]: Entering directory `C:/Users/syb0rg/Downloads/Khronos/build'
"C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\syb0rg\Downloads\Khronos C:\Users\syb0rg\Downloads\Khronos\src\util C:\Users\syb0rg\Downloads\Khronos\build C:\Users\syb0rg\Downloads\Khronos\build\src\util C:\Users\syb0rg\Downloads\Khronos\build\src\util\CMakeFiles\util.dir\DependInfo.cmake --color=
make[2]: Leaving directory `C:/Users/syb0rg/Downloads/Khronos/build'
make -f src\util\CMakeFiles\util.dir\build.make src/util/CMakeFiles/util.dir/build
make[2]: Entering directory `C:/Users/syb0rg/Downloads/Khronos/build'
make[2]: Nothing to be done for `src/util/CMakeFiles/util.dir/build'.
make[2]: Leaving directory `C:/Users/syb0rg/Downloads/Khronos/build'
[ 75%] Built target util
make -f src\CMakeFiles\main.dir\build.make src/CMakeFiles/main.dir/depend
make[2]: Entering directory `C:/Users/syb0rg/Downloads/Khronos/build'
"C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\syb0rg\Downloads\Khronos C:\Users\syb0rg\Downloads\Khronos\src C:\Users\syb0rg\Downloads\Khronos\build C:\Users\syb0rg\Downloads\Khronos\build\src C:\Users\syb0rg\Downloads\Khronos\build\src\CMakeFiles\main.dir\DependInfo.cmake --color=
make[2]: Leaving directory `C:/Users/syb0rg/Downloads/Khronos/build'
make -f src\CMakeFiles\main.dir\build.make src/CMakeFiles/main.dir/build
make[2]: Entering directory `C:/Users/syb0rg/Downloads/Khronos/build'
make[2]: Nothing to be done for `src/CMakeFiles/main.dir/build'.
make[2]: Leaving directory `C:/Users/syb0rg/Downloads/Khronos/build'
[ 80%] Built target main
make -f CMakeFiles\tritium.dir\build.make CMakeFiles/tritium.dir/depend
make[2]: Entering directory `C:/Users/syb0rg/Downloads/Khronos/build'
"C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\syb0rg\Downloads\Khronos C:\Users\syb0rg\Downloads\Khronos C:\Users\syb0rg\Downloads\Khronos\build C:\Users\syb0rg\Downloads\Khronos\build C:\Users\syb0rg\Downloads\Khronos\build\CMakeFiles\tritium.dir\DependInfo.cmake --color=
make[2]: Leaving directory `C:/Users/syb0rg/Downloads/Khronos/build'
make -f CMakeFiles\tritium.dir\build.make CMakeFiles/tritium.dir/build
make[2]: Entering directory `C:/Users/syb0rg/Downloads/Khronos/build'
make[2]: Nothing to be done for `CMakeFiles/tritium.dir/build'.
make[2]: Leaving directory `C:/Users/syb0rg/Downloads/Khronos/build'
[ 97%] Built target tritium
make -f CMakeFiles\Khronos.dir\build.make CMakeFiles/Khronos.dir/depend
make[2]: Entering directory `C:/Users/syb0rg/Downloads/Khronos/build'
"C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\syb0rg\Downloads\Khronos C:\Users\syb0rg\Downloads\Khronos C:\Users\syb0rg\Downloads\Khronos\build C:\Users\syb0rg\Downloads\Khronos\build C:\Users\syb0rg\Downloads\Khronos\build\CMakeFiles\Khronos.dir\DependInfo.cmake --color=
make[2]: Leaving directory `C:/Users/syb0rg/Downloads/Khronos/build'
make -f CMakeFiles\Khronos.dir\build.make CMakeFiles/Khronos.dir/build
make[2]: Entering directory `C:/Users/syb0rg/Downloads/Khronos/build'
[100%] Linking C executable Khronos.exe
"C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_link_script CMakeFiles\Khronos.dir\link.txt --verbose=1
"C:\Program Files (x86)\CMake\bin\cmake.exe" -E remove -f CMakeFiles\Khronos.dir/objects.a
C:\PROGRA~1\MINGW-~1\X86_64~1.0-P\mingw64\bin\ar.exe cr CMakeFiles\Khronos.dir/objects.a @CMakeFiles\Khronos.dir\objects1.rsp
C:\PROGRA~1\MINGW-~1\X86_64~1.0-P\mingw64\bin\gcc.exe     -Wl,--whole-archive CMakeFiles\Khronos.dir/objects.a -Wl,--no-whole-archive  -o Khronos.exe -Wl,--out-implib,libKhronos.dll.a -Wl,--major-image-version,0,--minor-image-version,0 @CMakeFiles\Khronos.dir\linklibs.rsp
CMakeFiles\Khronos.dir/objects.a(main.c.obj):main.c:(.text+0xd2): undefined reference to `ps_start_utt'
CMakeFiles\Khronos.dir/objects.a(main.c.obj):main.c:(.text+0x109): undefined reference to `ps_process_raw'
CMakeFiles\Khronos.dir/objects.a(main.c.obj):main.c:(.text+0x115): undefined reference to `ps_get_in_speech'
CMakeFiles\Khronos.dir/objects.a(main.c.obj):main.c:(.text+0x161): undefined reference to `ps_end_utt'
CMakeFiles\Khronos.dir/objects.a(main.c.obj):main.c:(.text+0x172): undefined reference to `ps_get_hyp'
CMakeFiles\Khronos.dir/objects.a(main.c.obj):main.c:(.text+0x185): undefined reference to `ps_start_utt'
CMakeFiles\Khronos.dir/objects.a(main.c.obj):main.c:(.text+0x1ce): undefined reference to `ps_end_utt'
CMakeFiles\Khronos.dir/objects.a(main.c.obj):main.c:(.text+0x1e8): undefined reference to `ps_get_hyp'
CMakeFiles\Khronos.dir/objects.a(main.c.obj):main.c:(.text+0x24b): undefined reference to `getPathFromDescriptor'
CMakeFiles\Khronos.dir/objects.a(main.c.obj):main.c:(.text+0x61c): undefined reference to `err_set_logfp'
CMakeFiles\Khronos.dir/objects.a(main.c.obj):main.c:(.text+0x626): undefined reference to `err_set_debug_level'
CMakeFiles\Khronos.dir/objects.a(main.c.obj):main.c:(.text+0x678): undefined reference to `ps_args'
CMakeFiles\Khronos.dir/objects.a(main.c.obj):main.c:(.text+0x6d7): undefined reference to `cmd_ln_init'
CMakeFiles\Khronos.dir/objects.a(main.c.obj):main.c:(.text+0x71f): undefined reference to `ps_init'
CMakeFiles\Khronos.dir/objects.a(main.c.obj):main.c:(.text+0x7fb): undefined reference to `ps_free'
CMakeFiles\Khronos.dir/objects.a(main.c.obj):main.c:(.text+0x807): undefined reference to `cmd_ln_free_r'
collect2.exe: error: ld returned 1 exit status
make[2]: *** [Khronos.exe] Error 1
make[2]: Leaving directory `C:/Users/syb0rg/Downloads/Khronos/build'
make[1]: *** [CMakeFiles/Khronos.dir/all] Error 2
make[1]: Leaving directory `C:/Users/syb0rg/Downloads/Khronos/build'
make: *** [all] Error 2

Here's the ${LIBS} output from message() (in a more human readable form):

C:/Users/syb0rg/Downloads/Khronos/lib/sphinxbase/bin/Debug/Win32/sphinxbase.dll
C:/Users/syb0rg/Downloads/Khronos/lib/pocketsphinx/bin/Debug/Win32/pocketsphinx.dll
C:/Users/syb0rg/Downloads/Khronos/lib/PortAudio/libportaudio_x86.dll
C:/Users/syb0rg/Downloads/Khronos/lib/LibSndFile/libsndfile.dll
C:/Users/syb0rg/Downloads/Khronos/lib/tritium/libtritium.a

For reference, ${LIBS} is set here:

FIND_PACKAGE(sphinxbase)
if (${SPHINXBASE_FOUND})
    INCLUDE_DIRECTORIES(${SPHINXBASE_INCLUDE_DIR}/sphinxbase/)
else ()
    ExternalProject_Add(
        sphinxbase
        GIT_REPOSITORY      "https://github.com/cmusphinx/sphinxbase.git"
        SOURCE_DIR          ${CMAKE_CURRENT_SOURCE_DIR}/lib/sphinxbase
        CONFIGURE_COMMAND   ""
        BUILD_COMMAND       msbuild sphinxbase.sln /p:PlatformToolset=v140
        UPDATE_COMMAND      ""
        INSTALL_COMMAND     ""
        BUILD_IN_SOURCE     ON
        LOG_DOWNLOAD        ON
        LOG_UPDATE          ON
        LOG_CONFIGURE       ON
        LOG_BUILD           ON
        LOG_TEST            ON
        LOG_INSTALL         ON
    )
    ExternalProject_Get_Property(sphinxbase SOURCE_DIR)
    ExternalProject_Get_Property(sphinxbase BINARY_DIR)
    SET(SPHINXBASE_SOURCE_DIR ${SOURCE_DIR})
    SET(SPHINXBASE_BINARY_DIR ${BINARY_DIR})
    SET(SPHINXBASE_LIBRARIES ${SPHINXBASE_BINARY_DIR}/bin/Debug/Win32/sphinxbase.dll)
    SET(DEPENDENCIES ${DEPENDENCIES} sphinxbase)
    INCLUDE_DIRECTORIES(${SPHINXBASE_SOURCE_DIR}/include/win32)
    INCLUDE_DIRECTORIES(${SPHINXBASE_SOURCE_DIR}/include)
endif ()
SET(LIBS ${LIBS} ${SPHINXBASE_LIBRARIES})

FIND_PACKAGE(pocketsphinx)
if (${POCKETSPHINX_FOUND})
    INCLUDE_DIRECTORIES(${POCKETSPHINX_INCLUDE_DIR}/pocketsphinx/)
    add_definitions( -DMODELDIR="/usr/local/share/pocketsphinx/model")  # more portable?
else ()
    ExternalProject_Add(
        pocketsphinx
        DEPENDS             sphinxbase
        GIT_REPOSITORY      "https://github.com/cmusphinx/pocketsphinx.git"
        SOURCE_DIR          ${CMAKE_CURRENT_SOURCE_DIR}/lib/pocketsphinx
        CONFIGURE_COMMAND   ""
        BUILD_COMMAND       msbuild pocketsphinx.sln /p:PlatformToolset=v140
        UPDATE_COMMAND      ""
        INSTALL_COMMAND     ""
        BUILD_IN_SOURCE     ON
        LOG_DOWNLOAD        ON
        LOG_UPDATE          ON
        LOG_CONFIGURE       ON
        LOG_BUILD           ON
        LOG_TEST            ON
        LOG_INSTALL         ON
        )
    ExternalProject_Get_Property(pocketsphinx SOURCE_DIR)
    ExternalProject_Get_Property(pocketsphinx BINARY_DIR)
    SET(POCKETSPHINX_SOURCE_DIR ${SOURCE_DIR})
    SET(POCKETSPHINX_BINARY_DIR ${BINARY_DIR})
    SET(POCKETSPHINX_LIBRARIES ${POCKETSPHINX_BINARY_DIR}/bin/Debug/Win32/pocketsphinx.dll)
    SET(DEPENDENCIES ${DEPENDENCIES} pocketsphinx)
    INCLUDE_DIRECTORIES(${POCKETSPHINX_SOURCE_DIR}/include/)
    add_definitions(-DMODELDIR="${POCKETSPHINX_BINARY_DIR}/model")
endif ()
SET(LIBS ${LIBS} ${POCKETSPHINX_LIBRARIES})

FIND_PACKAGE(PortAudio)
if (${PORTAUDIO_FOUND})
    INCLUDE_DIRECTORIES(${PORTAUDIO_INCLUDE_DIRS})
else ()
    ExternalProject_Add(
        PortAudio
        GIT_REPOSITORY      "https://github.com/syb0rg/PortAudio2.git"
        SOURCE_DIR          ${CMAKE_CURRENT_SOURCE_DIR}/lib/PortAudio
        UPDATE_COMMAND      ""
        INSTALL_COMMAND     ""
        BUILD_IN_SOURCE     ON
        LOG_DOWNLOAD        ON
        LOG_UPDATE          ON
        LOG_CONFIGURE       ON
        LOG_BUILD           ON
        LOG_TEST            ON
        LOG_INSTALL         ON
    )
    ExternalProject_Get_Property(PortAudio SOURCE_DIR)
    ExternalProject_Get_Property(PortAudio BINARY_DIR)
    SET(PORTAUDIO_SOURCE_DIR ${SOURCE_DIR})
    SET(PORTAUDIO_BINARY_DIR ${BINARY_DIR})
    SET(PORTAUDIO_LIBRARIES ${PORTAUDIO_BINARY_DIR}/libportaudio_x86.dll)
    SET(DEPENDENCIES ${DEPENDENCIES} PortAudio)
    INCLUDE_DIRECTORIES(${PORTAUDIO_SOURCE_DIR}/include)
endif ()
SET(LIBS ${LIBS} ${PORTAUDIO_LIBRARIES})

FIND_PACKAGE(LibSndFile)
if(${LIBSNDFILE_FOUND})
    INCLUDE_DIRECTORIES(${LIBSNDFILE_INCLUDE_DIRS})
else ()
    ExternalProject_Add(
        LibSndFile
        GIT_REPOSITORY      "https://github.com/syb0rg/libsndfile.git"
        SOURCE_DIR          ${CMAKE_CURRENT_SOURCE_DIR}/lib/LibSndFile
        UPDATE_COMMAND      ""
        INSTALL_COMMAND     ""
        BUILD_IN_SOURCE     ON
        LOG_DOWNLOAD        ON
        LOG_UPDATE          ON
        LOG_CONFIGURE       ON
        LOG_BUILD           ON
        LOG_TEST            ON
        LOG_INSTALL         ON
    )
    ExternalProject_Get_Property(LibSndFile SOURCE_DIR)
    ExternalProject_Get_Property(LibSndFile BINARY_DIR)
    SET(LIBSNDFILE_SOURCE_DIR ${SOURCE_DIR}/src)
    SET(LIBSNDFILE_BINARY_DIR ${BINARY_DIR})
    SET(LIBSNDFILE_LIBRARIES ${LIBSNDFILE_BINARY_DIR}/libsndfile.dll)
    SET(DEPENDENCIES ${DEPENDENCIES} LibSndFile)
    INCLUDE_DIRECTORIES(${LIBSNDFILE_SOURCE_DIR})
endif ()
SET(LIBS ${LIBS} ${LIBSNDFILE_LIBRARIES})

FIND_PACKAGE(tritium)
if (${TRITIUM_FOUND})
    INCLUDE_DIRECTORIES(${TRITIUM_INCLUDE_DIR}/)
else ()
    ExternalProject_Add(
        tritium
        GIT_REPOSITORY  "https://github.com/syb0rg/tritium.git"
        SOURCE_DIR      ${CMAKE_CURRENT_SOURCE_DIR}/lib/tritium
        UPDATE_COMMAND  ""
        INSTALL_COMMAND ""
        BUILD_IN_SOURCE ON
        LOG_DOWNLOAD    ON
        LOG_UPDATE      ON
        LOG_CONFIGURE   ON
        LOG_BUILD       ON
        LOG_TEST        ON
        LOG_INSTALL     ON
    )
    ExternalProject_Get_Property(tritium SOURCE_DIR)
    ExternalProject_Get_Property(tritium BINARY_DIR)
    SET(TRITIUM_SOURCE_DIR ${SOURCE_DIR})
    SET(TRITIUM_BINARY_DIR ${BINARY_DIR})
    SET(TRITIUM_LIBRARIES ${TRITIUM_BINARY_DIR}/libtritium.a)
    SET(DEPENDENCIES ${DEPENDENCIES} tritium)
    INCLUDE_DIRECTORIES(${TRITIUM_SOURCE_DIR}/include)
endif ()
SET(LIBS ${LIBS} ${TRITIUM_LIBRARIES})

All of these libraries exist at the specified location. Any suggestions?

syb0rg
  • 8,057
  • 9
  • 41
  • 81
  • There is no *LIBS* setting in your top-level `CMakeLists.txt`. Where is this variable set? – Tsyvarev Jul 18 '16 at 22:21
  • @Tsyvarev For Windows they are set in [`Win32_ExternalProjects.txt`](https://github.com/syb0rg/Khronos/blob/master/cmake/Win32-ExternalProjects.txt) – syb0rg Jul 18 '16 at 22:22
  • 3
    How does this question receive three upvotes? This is more or less a dump of files and output. The problem is not reduced and will not be helpful to others. – usr1234567 Jul 19 '16 at 14:11
  • 4
    @usr1234567 Because the question is clear, understandable, and may relate to others in the future? This question is also as reduced as I could make it to contain necessary info, just because it may not seem like it doesn't mean it isn't. On another note, please make only relevant, necessary edits in the future. – syb0rg Jul 19 '16 at 14:16
  • @syb0rg The [windows] tag is wrongly used, as your question is unrelated to the Windows API. [build] is very generic, especially in combination with [cmake] it does not add any value. Similar to [linker], which I could understand to keep in the question. Your CMakeLists.txt contains lots of clutter which makes it unnecessary difficult to get the point of the file. It is not complete as the included files are not part of the question. – usr1234567 Jul 19 '16 at 15:42
  • @usr1234567 All tags are correctly used. This issue is only reproduced on Windows systems (I haven't encountered in on Linux or Mac tests), it has to do with building my code along with other projects which are then linked to my code. If you would like to discuss reducing the `CMakelists.txt` further, we can talk [here](https://chat.stackexchange.com/rooms/8595/the-2nd-monitor). It's as complete as it needs to be while keeping the question minimal. If someone needs further resources, I'll provide them as quickly as possible (as seen from the first comments). – syb0rg Jul 19 '16 at 15:57
  • Could you please add the content of `Win32-ExternalProjects.txt`? If I understand it correctly the `LIBS` variable is set there. Just from the `LIBS` content it looks like you are trying to link against an DLL, but you should link against the import library (see [here](https://cmake.org/Wiki/CMake/Tutorials/Exporting_and_Importing_Targets#Exporting_from_an_Installation_Tree): [`IMPORTED_LOCATION`](https://cmake.org/cmake/help/latest/prop_tgt/IMPORTED_LOCATION.html) and [`IMPORTED_IMPLIB`](https://cmake.org/cmake/help/latest/prop_tgt/IMPORTED_IMPLIB.html). – Florian Jul 22 '16 at 08:49
  • And maybe ["Static and Dynamic/Shared Linking with MinGW"](http://stackoverflow.com/questions/15852677/static-and-dynamic-shared-linking-with-mingw) helps with some background information. – Florian Jul 22 '16 at 08:50
  • @Florian Edited in, sorry for the delay; I'm on vacation using the mobile SE app – syb0rg Jul 22 '16 at 13:03
  • 1
    It would help if you could provide us with the actual link command used. To do this you would need to "make VERBOSE=1" and then paste the link line. The functions that are missing are not standard functions and knowing nothing about your application, I can only intuit that from the name "Pocket Sphinx" and the functions mostly beginning with "ps_" that what is actually happening is that the pocketsphinx library isn't being correctly linked in. – Kean Jul 23 '16 at 12:41
  • @Kean Edited in verbose output – syb0rg Jul 25 '16 at 13:22
  • 1
    @syb0rg The question as it stands now is pretty much unanswerable I'm afraid, as it basically boils down to debugging your build system. I can see a bunch of issues there that don't seem kosher, but it's very hard to tell which one causes that linker error in the end, without spending an hour or two cleaning up your build. If you could narrow the problem down to a single project linking against the single external lib that causes the problem, your chances of getting useful answers would increase dramatically. – ComicSansMS Jul 25 '16 at 13:39
  • @ComicSansMS There is only a single project being linked, and from the output it seems that `PocketSphinx` is the problem (both identifiable from the question text). This question isn't going to be easy to answer, if it was I wouldn't have asked it and put a bounty on it (rather found the solution myself). – syb0rg Jul 25 '16 at 13:42

2 Answers2

5

undefined reference to clearly stated you do not provide required object file/library with this (exported!) function to linker. There are two major causes:

  1. You didn't pass this library to linker command line or didn't pass right search path (-L...) to it - check twice the resulting command line, make VERBOSE=1 will show more verbose output.
  2. Path is correct, but file/function itself is invalid - you may compile library for different CPU architecture (e.g. trying to use x86 library when targeting x86_64). Also check function marked as exportable (in most cases it is the problem when using MSVC compiler, but you can hide functions with GCC/MinGW too). And do not forgot to check file is not zero-length :)
vitalyster
  • 4,980
  • 3
  • 19
  • 27
  • Did you mean `make VERBOSE=1`? And what do you mean by "exportable"? I've never heard of such a thing. – syb0rg Jul 21 '16 at 19:34
  • Guys, what's wrong with this answer? As for me, it offers clear troubleshooting steps. First you should check if you are actually linking against the library, second you should check if your library exports necessary symbols. – ivaigult Jul 25 '16 at 09:22
  • 1
    @syb0rg: Yes, `make VERBOSE=1` was meant. By "exportable" linker visibility is meant. Thought, by default gcc exports _all_ non static symbols while MSVC and MinGW exports functions with `__declspec(dllexport)` attribute only. Also MSVC and MinGW might change symbol names for non default calling conventions. – ivaigult Jul 25 '16 at 09:35
  • Ah, the issue turned to be that `msbuild` was generating 32-bit libraries while all my other external libraries were 64-bit. An easy fix, once identified. Thanks! – syb0rg Jul 25 '16 at 14:35
  • @ivaigult This would be better a comment, as it is unspecific regarding the question. I don't know how this answer could get five upvotes. *shrug* – usr1234567 Jul 26 '16 at 16:21
-2

Can you try this:

set(CMAKE_BUILD_TYPE CACHE Release FORCE)

ref: https://cmake.org/cmake/help/v2.8.8/cmake.html#variable:CMAKE_CFG_INTDIR

search for : initial-cache

Arjun Iv
  • 1
  • 1