Linking LLVM libraries on Windows with CMake and MinGW - c++

I've been writing a compiler using LLVM as the backend. The CMake files I've written so far have worked on Linux, but I haven't had any luck on Windows. The project is split into a library and "driver" executable with their own CMakeLists.txt in separate subdirectories.
The top level CMakeLists.txt looks like this:
cmake_minimum_required (VERSION 3.7.0)
project (compiler)
set (CMAKE_CXX_STANDARD 14)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
set (CMAKE_CXX_EXTENSIONS OFF)
find_package (LLVM REQUIRED CONFIG)
message (STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message (STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
include_directories (${LLVM_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})
add_subdirectory (Compiler_Lib)
add_subdirectory (Compiler_exe)
The CMakeLists.txt for the library:
cmake_minimum_required (VERSION 3.7.0)
add_library (compiler_lib
AST.cpp
AST.h
parser.cpp
parser.h
scanner.cpp
scanner.h
token.cpp
token.h
visualizer.cpp
visualizer.h
codegen.cpp
codegen.h)
target_include_directories (compiler_lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(compiler_lib LLVM)
And the CMakeLists.txt for the executable (which is where linking to the libraries fails):
cmake_minimum_required (VERSION 3.7.0)
project (compiler_exe)
add_executable (compiler_exe Compiler_exe.cpp getopt.h getopt.cpp)
target_link_libraries (compiler_exe LINK_PUBLIC LLVM compiler_lib)
I run the command "c:\Program Files\CMake\bin\cmake.exe" .. -G"MinGW Makefiles" -DCMAKE_PREFIX_PATH=C:\Users\James\llvm+clang-7.0.0-win64-msvc-release where C:\Users\James\llvm+clang-7.0.0-win64-msvc-release is the path to prebuilt LLVM libraries. However, running mingw32-make afterwards fails with the output
Scanning dependencies of target compiler_lib
[ 10%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/AST.cpp.obj
[ 20%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/parser.cpp.obj
[ 30%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/scanner.cpp.obj
[ 40%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/token.cpp.obj
[ 50%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/visualizer.cpp.obj
[ 60%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/codegen.cpp.obj
[ 70%] Linking CXX static library libcompiler_lib.a
[ 70%] Built target compiler_lib
Scanning dependencies of target compiler_exe
[ 80%] Building CXX object Compiler_exe/CMakeFiles/compiler_exe.dir/Compiler_exe.cpp.obj
[ 90%] Building CXX object Compiler_exe/CMakeFiles/compiler_exe.dir/getopt.cpp.obj
[100%] Linking CXX executable compiler_exe.exe
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: cannot find -lLLVM
collect2.exe: error: ld returned 1 exit status
Compiler_exe\CMakeFiles\compiler_exe.dir\build.make:102: recipe for target 'Compiler_exe/compiler_exe.exe' failed
mingw32-make[2]: *** [Compiler_exe/compiler_exe.exe] Error 1
CMakeFiles\Makefile2:176: recipe for target 'Compiler_exe/CMakeFiles/compiler_exe.dir/all' failed
mingw32-make[1]: *** [Compiler_exe/CMakeFiles/compiler_exe.dir/all] Error 2
Makefile:82: recipe for target 'all' failed
mingw32-make: *** [all] Error 2
This is the first time I've used CMake so I could have missed something obvious, but as I say it seems to work on Linux.

For the linking to succeed two things need to be true:
1) the file libLLVM.a needs to exist
2) that file has to be in a directory in the library search path
There should be a way to get cmake to tell you the list of places it searches for libraries, and you need to find a way to get wherever libLLVM.a exists into that list of dirs.
Apologies for the partial answer, but that's the troubleshooting path...

Related

Boost.Test linker error by use with precompiled headers (PCH)

I have a linker error when using Boost.Test with precompiled header (PCH) that does not occur without PCH. I use the dynamically linked library as described in Usage variants.
How can I fix the error to use Boost.Test also with PCH?
The problem occurs at least with Fedora and boost 1.73 (has only dynamic libraries) and g++ 10/clang 11.
$ cmake ../ && make
-- Configuring done
-- Generating done
-- Build files have been written to: /home/.../boost_test_pch/build
[ 33%] Building CXX object CMakeFiles/boost_utf_pch.dir/test_driver.cpp.o
[ 66%] Building CXX object CMakeFiles/boost_utf_pch.dir/test.cpp.o
[100%] Linking CXX executable boost_utf_pch
[100%] Built target boost_utf_pch
vs.
$ cmake -DEDA_ENABLE_PCH=TRUE ../ && make
-- Configuring done
-- Generating done
-- Build files have been written to: /home/.../boost_test_pch/build
[ 25%] Building CXX object CMakeFiles/boost_utf_pch.dir/cmake_pch.hxx.gch
[ 50%] Building CXX object CMakeFiles/boost_utf_pch.dir/test_driver.cpp.o
cc1plus: warning: /home/.../boost_test_pch/build/CMakeFiles/boost_utf_pch.dir/cmake_pch.hxx.gch: not used because `BOOST_TEST_DYN_LINK' is defined [-Winvalid-pch]
[ 75%] Building CXX object CMakeFiles/boost_utf_pch.dir/test.cpp.o
[100%] Linking CXX executable boost_utf_pch
/usr/bin/ld: /usr/lib/gcc/x86_64-redhat-linux/10/../../../../lib64/crt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/boost_utf_pch.dir/build.make:138: boost_utf_pch] Error 1
make[1]: *** [CMakeFiles/Makefile2:95: CMakeFiles/boost_utf_pch.dir/all] Error 2
make: *** [Makefile:103: all] Error 2
I can not do anything with the warning message before ...
Here the playground files:
CMakeLists.txt:
project(boost_utf_pch LANGUAGES CXX)
cmake_minimum_required(VERSION 3.18)
add_executable(${PROJECT_NAME} "")
find_package(Boost 1.73.0 REQUIRED COMPONENTS
unit_test_framework)
target_sources(${PROJECT_NAME} PRIVATE
test_driver.cpp test.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE
Boost::unit_test_framework)
set_source_files_properties(test_driver.cpp
APPEND PROPERTIES COMPILE_DEFINITIONS "BOOST_TEST_DYN_LINK")
option(EDA_ENABLE_PCH "Enable PCH" OFF)
if (EDA_ENABLE_PCH)
target_precompile_headers(${PROJECT_NAME} PRIVATE pch.hpp)
endif()
pch.hpp
#pragma once
#include <boost/test/unit_test.hpp>
test.cpp
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE( my_test )
BOOST_AUTO_TEST_CASE( test_case1 )
{
BOOST_TEST_WARN( sizeof(int) < 4U );
}
BOOST_AUTO_TEST_SUITE_END()
test_driver.cpp
#define BOOST_TEST_MODULE "Boost.UTF PCH Test Suite"
#include <boost/test/unit_test.hpp>
Alan Birtles got the hint into the right direction. I was not aware of the influence of the compiler switch BOOST_TEST_DYN_LINK for the single file in the context of PCH here. A definition for all files of the project in the style of:
target_compile_definitions(${PROJECT_NAME} PRIVATE
"BOOST_TEST_DYN_LINK")
incomprehensibly does not solve the problem. Only after setting the property SKIP_PRECOMPILE_HEADERS for driver 'main' it compiles and links as expected:
project(boost_utf_pch LANGUAGES CXX)
cmake_minimum_required(VERSION 3.18)
add_executable(${PROJECT_NAME} "")
find_package(Boost 1.73.0 REQUIRED COMPONENTS
unit_test_framework)
target_sources(${PROJECT_NAME} PRIVATE
test_driver.cpp test.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE
Boost::unit_test_framework)
set_source_files_properties(test_driver.cpp
APPEND PROPERTIES COMPILE_DEFINITIONS "BOOST_TEST_DYN_LINK")
set_source_files_properties(test_driver.cpp
PROPERTIES SKIP_PRECOMPILE_HEADERS ON)
option(EDA_ENABLE_PCH "Enable PCH" ON)
if (EDA_ENABLE_PCH)
target_precompile_headers(${PROJECT_NAME} PRIVATE pch.hpp)
endif()

CMake linking with dll on windows - undefined reference

I am trying to link with a DLL executable using CMake. This works fine on Linux (of course with .so), but on Windows, it seems to be tricky. I thought it might be some other dependencies, so I tried creating a simple test program, but I couldn't get that to work either.
My folder structure is simple:
main.cpp
CmakeLists.txt
lib/libtest.dll
lib/CMakeLists.txt
I based this structure on the answer to another question that was asked.
Unfortunately, when I build, it it fails.
The content of the lib/CMakeLists.txt are:
message("-- Linking Test")
add_library(TEST libtest.dll)
set_target_properties(TEST PROPERTIES LINKER_LANGUAGE C)
And the content of the main CMakeLists.txt are:
cmake_minimum_required(VERSION 3.15)
project(Test_program)
set(CMAKE_CXX_STANDARD 14)
set(GCC_COVERAGE_COMPILE_FLAGS "-DDebug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}" )
# Contain the header files for testlib
include_directories("C:/test/utils/")
add_subdirectory(lib)
add_executable(Test_program main.cpp)
target_link_libraries(Test_program TEST)
This results in the following output:
-- Linking Test
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/akda/Test_program/cmake-build-debug
[ 33%] Linking C static library libTEST.a
[ 33%] Built target TEST
[ 66%] Building CXX object CMakeFiles/Test_program.dir/main.cpp.obj
[100%] Linking CXX executable Test_program.exe
CMakeFiles\Test_program.dir/objects.a(main.cpp.obj): In function `powerOn()':
C:/Users/akda/Test_program/main.cpp:8: undefined reference to `My_Library_Function'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[2]: *** [CMakeFiles\Test_program.dir\build.make:87: Test_program.exe] Error 1
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:77: CMakeFiles/Test_program.dir/all] Error 2
mingw32-make.exe: *** [Makefile:83: all] Error 2
Using tools as DLLExportViewer, I can confirm that the DLL, in fact, does contain the function called.
What am I doing wrong? I'll never claim to be an expert in CMake, but I really can't see what's wrong.
Update with link to .a file
As pointed out, I could try linking with the .a file.
I've added this to the library folder, and changed the main CMakeLists.txt to the following:
cmake_minimum_required(VERSION 3.15)
project(Test_program)
set(CMAKE_CXX_STANDARD 14)
set(GCC_COVERAGE_COMPILE_FLAGS "-DDebug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}" )
include_directories("C:/test/utils/")
find_library(TEST ${CMAKE_SOURCE_DIR}/lib/libtest.a)
add_executable(Test_program main.cpp)
target_link_libraries(Test_program ${TEST})
And this ends up in the same way, with the same errors.

CMake error: linker command failed with exit code 1 and cpp.o files

I am using CMake to compile a small project.
Here is what I have written in CMakeLists.txt:
cmake_minimum_required(VERSION 3.2)
set (CMAKE_CXX_STANDARD 11)
project(DAF)
find_package(OpenCV REQUIRED)
include_directories(include)
include_directories(${OpenCV_INCLUDE_DIRS} )
file(GLOB Src_Sources "src/*.cpp")
file(GLOB Test_Sources "test/*.cpp")
add_executable(executable ${Src_Sources} ${Test_Sources})
target_link_libraries( executable include ${OpenCV_LIBS} )
I have two directories src and test. The src directory contains only the files that hold the functions, whereas the test directory contains the main file.
Once I use the cmake command and then the make command I get this error:
Scanning dependencies of target executation
[ 25%] Building CXX object CMakeFiles/executation.dir/src/image.cpp.o
[ 50%] Building CXX object CMakeFiles/executation.dir/test/starter_1.cpp.o
[ 75%] Linking CXX executable executation
ld: library not found for -linclude
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [executation] Error 1
make[1]: *** [CMakeFiles/executation.dir/all] Error 2
make: *** [all] Error 2
So what I find strange is that it creates .cpp.o files. Is that normal?
And then how do I fix the error library not found for -linclude?
Yes, it is normal for CMake to take the name of the source file, and append a .o when compiling the respective object files. For example, the source file image.cpp will be compiled into image.cpp.o. The Makefiles generated by CMake will contain a unique target <someSourceFileName>.o for each source file, where <someSourceFileName> can be a .cc, .cpp, .c, etc.
The error:
ld: library not found for -linclude
indicates that you have tried to link a library called include to the executable. This is likely not what you intend. It appears include is actually your include directory, and you have already specified the include directories in your CMake with this line:
include_directories(include)
To remove the error, just take out the include from the target_link_libraries() command, like so:
target_link_libraries( executable ${OpenCV_LIBS} )

GLM fails to build when using Clion

I am using the experimental GLM hash features in a CMake project.
Everything works fine unless the project is generated by Clion.
When building the Clion generated project GLM raises the error "GLM_GTX_hash requires C++11 standard library support" (see CMake logs) although C++11 is enabled.
Building the same, clion generated, project from a terminal fails with the same error.
However, when generating and building the project with cmake 'manually' (without Clion even knowing about it) everything works fine. As expected.
GLM is not directly included in the CMakeList. GLFW includes/imports it.
Example CMakeLists.txt
(...)
set(CMAKE_CXX_STANDARD 11)
add_executable(Test main.cpp)
(...)
add_subdirectory("glfw" ${CMAKE_CURRENT_BINARY_DIR}/glfw)
target_include_directories(Test PUBLIC ${GLFW_INCLUDE_DIRS})
target_link_libraries(Test ${GLFW_LIBRARIES} glfw)
Example main.cpp
#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/hash.hpp>
int main() {
return 0;
}
Clion build output:
/usr/bin/cmake --build /home/lukas/Test/cmake-build-debug --target Test -- -j 2
[ 89%] Built target glfw
Scanning dependencies of target Test
[ 94%] Building CXX object CMakeFiles/Test.dir/main.cpp.o
In file included from /home/lukas/Test/main.cpp:8:
/usr/include/glm/gtx/hash.hpp:46:3: error: "GLM_GTX_hash requires C++11 standard library support"
# error "GLM_GTX_hash requires C++11 standard library support"
^
1 error generated.
make[3]: *** [CMakeFiles/Test.dir/build.make:63: CMakeFiles/Test.dir/main.cpp.o] Error 1
make[2]: *** [CMakeFiles/Makefile2:73: CMakeFiles/Test.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:85: CMakeFiles/Test.dir/rule] Error 2
make: *** [Makefile:118: Test] Error 2
Terminal output (as expected)
$ cmake -H. -Bbuild -G "Unix Makefiles" && cmake --build build
Scanning dependencies of target glfw
[ 5%] Building C object glfw/src/CMakeFiles/glfw.dir/context.c.o
[ 10%] Building C object glfw/src/CMakeFiles/glfw.dir/init.c.o
[ 15%] Building C object glfw/src/CMakeFiles/glfw.dir/input.c.o
[ 21%] Building C object glfw/src/CMakeFiles/glfw.dir/monitor.c.o
[ 26%] Building C object glfw/src/CMakeFiles/glfw.dir/vulkan.c.o
[ 31%] Building C object glfw/src/CMakeFiles/glfw.dir/window.c.o
[ 36%] Building C object glfw/src/CMakeFiles/glfw.dir/x11_init.c.o
[ 42%] Building C object glfw/src/CMakeFiles/glfw.dir/x11_monitor.c.o
[ 47%] Building C object glfw/src/CMakeFiles/glfw.dir/x11_window.c.o
[ 52%] Building C object glfw/src/CMakeFiles/glfw.dir/xkb_unicode.c.o
[ 57%] Building C object glfw/src/CMakeFiles/glfw.dir/posix_time.c.o
[ 63%] Building C object glfw/src/CMakeFiles/glfw.dir/posix_thread.c.o
[ 68%] Building C object glfw/src/CMakeFiles/glfw.dir/glx_context.c.o
[ 73%] Building C object glfw/src/CMakeFiles/glfw.dir/egl_context.c.o
[ 78%] Building C object glfw/src/CMakeFiles/glfw.dir/osmesa_context.c.o
[ 84%] Building C object glfw/src/CMakeFiles/glfw.dir/linux_joystick.c.o
[ 89%] Linking C static library libglfw3.a
[ 89%] Built target glfw
Scanning dependencies of target Test
[ 94%] Building CXX object CMakeFiles/Test.dir/main.cpp.o
[100%] Linking CXX executable Test
[100%] Built target Test
Now I am actually curious about rather I messed up somewhere or if it is simply a bug. And if so, where should I report it?
[Clion/Jetbrains?, GLM?, GLFW?, CMake?]
Thanks in advance
Update
I am using the latest available (for me) builds:
CMake version: 3.14.4
Operating System: Arch Linux 5.0.18-1 x86_64 GNU/Linux
GLFW version/commit: d834f01c
GLM version/commit: fce2abd0
Clion: 2019.1.3
Clion EAP: 2019.2 EAP
Final update / 'Solution'
I just discovered that the problem is Clang, not Clion or anything else.
Clion simply defaulted to Clang (instead of GCC).
There are bug reports for GLM and Clang already existing (with potential fixes!):
https://github.com/g-truc/glm/issues/620
https://github.com/g-truc/glm/issues/646
Thank you very much everyone ~

Cmake error undefined symbols for x86_64

I am trying to compile the conv-net library in my mac osx yosemite with xcode. I even set the flags to libstdc++ still it is not linking properly.
i still get undefined symbols for architecture x86_64.
any help much appreciated.
sh-3.2# ./compile.sh
Building conv-net library
-- The C compiler identification is AppleClang 6.0.0.6000056
-- The CXX compiler identification is AppleClang 6.0.0.6000056
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
WARNING: Target "testimg" requests linking to directory "/usr/local/Cellar/opencv/2.4.9/lib". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "testimg" requests linking to directory "/usr/local/Cellar/opencv/2.4.9/lib". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "testmnist" requests linking to directory "/usr/local/Cellar/opencv/2.4.9/lib". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "testmnist" requests linking to directory "/usr/local/Cellar/opencv/2.4.9/lib". Targets may link only to libraries. CMake is dropping the item.
-- Generating done
-- Build files have been written to: /var/tmp/conv-net-0.1-prealpha_buildroot
Scanning dependencies of target cvconvnet
[ 11%] Building CXX object CMakeFiles/cvconvnet.dir/src/cvsubsamplingplane.cpp.o
[ 22%] Building CXX object CMakeFiles/cvconvnet.dir/src/cvconvolutionplane.cpp.o
[ 33%] Building CXX object CMakeFiles/cvconvnet.dir/src/cvgenericplane.cpp.o
[ 44%] Building CXX object CMakeFiles/cvconvnet.dir/src/cvsourceplane.cpp.o
[ 55%] Building CXX object CMakeFiles/cvconvnet.dir/src/cvrbfplane.cpp.o
[ 66%] Building CXX object CMakeFiles/cvconvnet.dir/src/cvmaxplane.cpp.o
[ 77%] Building CXX object CMakeFiles/cvconvnet.dir/src/cvconvnetparser.cpp.o
[ 88%] Building CXX object CMakeFiles/cvconvnet.dir/src/cvfastsigmoid.cpp.o
[100%] Building CXX object CMakeFiles/cvconvnet.dir/src/cvconvnet.cpp.o
/Users/prabhubalakrishnan/Desktop/conv-net/src/cvconvnet.cpp:169:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
1 warning generated.
Linking CXX static library libcvconvnet.a
[100%] Built target cvconvnet
Scanning dependencies of target testimg
Linking CXX executable testimg
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [testimg] Error 1
make[1]: *** [CMakeFiles/testimg.dir/all] Error 2
make: *** [all] Error 2
cp: testimg: No such file or directory
cp: testmnist: No such file or directory
ls: illegal option -- I
usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]
This is my make file
cmake_minimum_required(VERSION 3.0)
PROJECT (CvConvolutionalNet)
set (CMAKE_CXX_FLAGS " -stdlib=libstdc++")
# IF() ENDIF() statements
SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
# Specify build-type as Debug if not specified already
IF (NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE Debug)
ENDIF ()
# Produce verbose makefiles
# SET(CMAKE_VERBOSE_MAKEFILE ON)
# Sources for library
SET(CVCONVNET_SRCS
src/cvsubsamplingplane.cpp
src/cvconvolutionplane.cpp
src/cvgenericplane.cpp
src/cvsourceplane.cpp
src/cvrbfplane.cpp
src/cvmaxplane.cpp
src/cvconvnetparser.cpp
src/cvfastsigmoid.cpp
src/cvconvnet.cpp
)
# Sources for test files
SET(TESTIMG_SRCS tst/)
SET(TESTMNIST_SRCS tst/)
set (CV_H /usr/local/Cellar/opencv/2.4.9/include/opencv)
set (HIGHGUI_H src/include )
set (LIBCV /usr/local/Cellar/opencv/2.4.9/lib )
set (LIBHIGHGUI /usr/local/Cellar/opencv/2.4.9/lib )
# Here are common paths (in addition to default paths)
SET (INCLUDE_SEARCH_PATH
/usr/local/include /usr/include /usr/include/opencv/
/usr/include/opencv/ c:/program\ files/opencv/include
)
SET (LIBRARY_SEARCH_PATH
/usr/local/lib /usr/lib c:/program\ files/opencv/lib c:/windows/system32
)
# Find OpenCV and Expat
FIND_PATH(CV_H NAMES cv.h PATHS ${INCLUDE_SEARCH_PATH} )
FIND_PATH(HIGHGUI_H NAMES highgui.h PATHS ${INCLUDE_SEARCH_PATH} )
FIND_PATH(EXPAT_H NAMES expat.h PATHS ${INCLUDE_SEARCH_PATH} )
FIND_LIBRARY(LIBCV NAMES cv PATHS ${LIBRARY_SEARCH_PATH} )
FIND_LIBRARY(LIBHIGHGUI NAMES highgui PATHS ${LIBRARY_SEARCH_PATH} )
FIND_LIBRARY(LIBEXPAT NAMES expat PATHS ${LIBRARY_SEARCH_PATH} )
INCLUDE_DIRECTORIES(include/ ${CV_H} ${HIGHGUI_H} ${EXPAT_H})
# Here is out library
ADD_LIBRARY(cvconvnet STATIC ${CVCONVNET_SRCS})
# Here are our test programs
ADD_EXECUTABLE(testimg ${TESTIMG_SRCS})
ADD_EXECUTABLE(testmnist ${TESTMNIST_SRCS})
# Compiler options are different for Release and Debug
IF (CMAKE_BUILD_TYPE MATCHES Release)
# Highly optimized + cancel all assert()s
ADD_DEFINITIONS(-O3 -DNDEBUG)
ELSE ()
# Include debug info, profiling info, some text output
ADD_DEFINITIONS(-O -pg -g -DDEBUG)
# Set profiling for linker too
SET_TARGET_PROPERTIES(testmnist PROPERTIES LINK_FLAGS "-pg")
ENDIF ()
# We should link our test programs to libraries
TARGET_LINK_LIBRARIES(testimg cvconvnet ${LIBCV} ${LIBHIGHGUI} ${LIBEXPAT})
TARGET_LINK_LIBRARIES(testmnist cvconvnet ${LIBCV} ${LIBHIGHGUI} ${LIBEXPAT})
I fixed it by adding -c option in the compiler flags and it worked !!!!
The add_executable command takes a target name and a list of source files to be compiled. When you are creating a target for testimg you are passing it directory.
Use file(GLOB ...) command to gather all source files from directory into a list variable and pass it to add_executable call.