OpenCV makefile doesn't generate exectuable - c++

I'm new to C++ and I'm trying to recreate the openCV tutorial with Cmake https://docs.opencv.org/master/db/df5/tutorial_linux_gcc_cmake.html
I downloaded the .exe for windows, built the sources with cmake via
cmake.exe -G "MinGW Makefiles"
Then, I tried to use the make command in the project folder with the debug flag. I received this output:
GNU Make 4.2.1
Built for i686-pc-msys
Copyright (C) 1988-2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Reading makefile 'Makefile'...
Updating makefiles....
Considering target file 'Makefile'.
Looking for an implicit rule for 'Makefile'.
No implicit rule found for 'Makefile'.
Finished prerequisites of target file 'Makefile'.
No need to remake target 'Makefile'.
Updating goal targets....
Considering target file 'default_target'.
File 'default_target' does not exist.
Considering target file 'all'.
File 'all' does not exist.
Considering target file 'cmake_check_build_system'.
File 'cmake_check_build_system' does not exist.
Finished prerequisites of target file 'cmake_check_build_system'.
Must remake target 'cmake_check_build_system'.
Putting child 0x2004f248 (cmake_check_build_system) PID 22640 on the chain.
Live child 0x2004f248 (cmake_check_build_system) PID 22640
Microsoft Windows [Version 10.0.18362.836]
(c) 2019 Microsoft Corporation. All rights reserved.
I don't quite understand the output and googling for this didn't prove to be helpful. Since I don't have an executable file at the end (as mentioned in the tutorial), there seems to be some problem. What am I missing?
The CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
set(OpenCV_DIR "C:/Users/XXX/opencv/opencv")
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
CMake output:
cmake.exe -G "MinGW Makefiles"
CMake Warning:
No source or binary directory provided. Both will be assumed to be the
same as the current working directory, but note that this warning will
become a fatal error in future CMake releases.
-- The C compiler identification is GNU 4.9.3
-- The CXX compiler identification is GNU 4.9.3
-- Check for working C compiler: C:/Rtools/mingw_64/bin/gcc.exe
-- Check for working C compiler: C:/Rtools/mingw_64/bin/gcc.exe - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Rtools/mingw_64/bin/g++.exe
-- Check for working CXX compiler: C:/Rtools/mingw_64/bin/g++.exe - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenCV: C:/Users/XXX/opencv/opencv (found version "4.3.0")
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/XXX/Documents/C++
make output (minGW-32)
mingw32-make.exe VERBOSE=1
"C:\Program Files\CMake\bin\cmake.exe" -SC:\Users\XXX\Documents\C++ -BC:\Users\XXX\Documents\C++ --check-build-system CMakeFiles\Makefile.cmake 0
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_progress_start C:\Users\XXX\Documents\C++\CMakeFiles C:\Users\XXX\Documents\C++\CMakeFiles\progress.marks
mingw32-make.exe -f CMakeFiles\Makefile2 all
mingw32-make.exe[1]: Entering directory 'C:/Users/XXX/Documents/C++'
mingw32-make.exe -f CMakeFiles\DisplayImage.dir\build.make CMakeFiles/DisplayImage.dir/depend
mingw32-make.exe[2]: Entering directory 'C:/Users/XXX/Documents/C++'
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\XXX\Documents\C++ C:\Users\XXX\Documents\C++ C:\Users\XXX\Documents\C++ C:\Users\XXX\Documents\C++ C:\Users\XXX\Documents\C++\CMakeFiles\DisplayImage.dir\DependInfo.cmake --color=
mingw32-make.exe[2]: Leaving directory 'C:/Users/XXX/Documents/C++'
mingw32-make.exe -f CMakeFiles\DisplayImage.dir\build.make CMakeFiles/DisplayImage.dir/build
mingw32-make.exe[2]: Entering directory 'C:/Users/XXX/Documents/C++'
mingw32-make.exe[2]: *** No rule to make target 'C:/Users/XXX/opencv_mingw/sources/build_mingw/lib/libopencv_dnn430.dll.a', needed by 'DisplayImage.exe'. Stop.
mingw32-make.exe[2]: Leaving directory 'C:/Users/XXX/Documents/C++'
CMakeFiles\Makefile2:94: recipe for target 'CMakeFiles/DisplayImage.dir/all' failed
mingw32-make.exe[1]: *** [CMakeFiles/DisplayImage.dir/all] Error 2
mingw32-make.exe[1]: Leaving directory 'C:/Users/XXX/Documents/C++'
makefile:102: recipe for target 'all' failed
mingw32-make.exe: *** [all] Error 2

Related

Build issues with shared_mutex and MinGW-w64

I'm currently working on a C++14 project, using MinGW-w64 and a CMake configuration (MinGW Makefile generator). I'm having a hard time building it due to compatibility issues with the shared_mutex library. To circumnavigate such problems, I'm using a custom header-only library called mingw-std-threads. After following all the instructions of the library's mark-down file, I still have errors with shared_mutex.
Here's a minimal reproducible example of the error I am getting. Source file:
#include <shared_mutex>
int main()
{
return 0;
}
The CMake configuration for the test:
# CMake 3.9 or newer
cmake_minimum_required(VERSION 3.9)
# project name, version and description
project(test)
# C++14 or higher
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# library target
add_executable(test test.cpp)
# include directories
target_include_directories(test PRIVATE .)
#MinGW threads
option(MINGW_STDTHREADS_GENERATE_STDHEADERS "" ON)
add_subdirectory(./mingw-std-threads-master)
target_link_libraries(test PRIVATE mingw_stdthreads)
# defining install rules
include(GNUInstallDirs)
install(TARGETS test
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
The project generation log:
PS C:\Users\luigi\Desktop\test> cmake --version
cmake version 3.18.3
CMake suite maintained and supported by Kitware (kitware.com/cmake).
PS C:\Users\luigi\Desktop\test> cmake -G "MinGW Makefiles" -S ./ -B build/
-- The C compiler identification is GNU 8.1.0
-- The CXX compiler identification is GNU 8.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/mingw-w64/mingw64/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/mingw-w64/mingw64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
cmake_stdheaders_generator: output_include_path set to C:/Users/luigi/Desktop/test/build/mingw-std-threads-master/cmake_stdheaders_generator/cmake_stdheaders_generator
cmake_stdheaders_generator: MINGW_STDTHREADS_DIR: C:/Users/luigi/Desktop/test/mingw-std-threads-master
Matched: <C:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/condition_variable>
Matched: <C:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/future>
Matched: <C:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/mutex>
Matched: <C:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/shared_mutex>
Matched: <C:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/thread>
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/luigi/Desktop/test/build
PS C:\Users\luigi\Desktop\test>
The resulting build log with the error:
PS C:\Users\luigi\Desktop\test> cmake --build ./build -v
"C:\Program Files\CMake\bin\cmake.exe" -SC:\Users\luigi\Desktop\test -BC:\Users\luigi\Desktop\test\build --check-build-system CMakeFiles\Makefile.cmake 0
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_progress_start C:\Users\luigi\Desktop\test\build\CMakeFiles C:\Users\luigi\Desktop\test\build\\CMakeFiles\progress.marks
C:/mingw-w64/mingw64/bin/mingw32-make.exe -f CMakeFiles\Makefile2 all
mingw32-make.exe[1]: Entering directory 'C:/Users/luigi/Desktop/test/build'
C:/mingw-w64/mingw64/bin/mingw32-make.exe -f CMakeFiles\test.dir\build.make CMakeFiles/test.dir/depend
mingw32-make.exe[2]: Entering directory 'C:/Users/luigi/Desktop/test/build'
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\luigi\Desktop\test C:\Users\luigi\Desktop\test C:\Users\luigi\Desktop\test\build C:\Users\luigi\Desktop\test\build C:\Users\luigi\Desktop\test\build\CMakeFiles\test.dir\DependInfo.cmake --color=
Dependee "C:\Users\luigi\Desktop\test\build\CMakeFiles\test.dir\DependInfo.cmake" is newer than depender "C:/Users/luigi/Desktop/test/build/CMakeFiles/test.dir/depend.internal".
Dependee "C:/Users/luigi/Desktop/test/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "C:/Users/luigi/Desktop/test/build/CMakeFiles/test.dir/depend.internal".
Scanning dependencies of target test
mingw32-make.exe[2]: Leaving directory 'C:/Users/luigi/Desktop/test/build'
C:/mingw-w64/mingw64/bin/mingw32-make.exe -f CMakeFiles\test.dir\build.make CMakeFiles/test.dir/build
mingw32-make.exe[2]: Entering directory 'C:/Users/luigi/Desktop/test/build'
[ 50%] Building CXX object CMakeFiles/test.dir/test.cpp.obj
C:\mingw-w64\mingw64\bin\g++.exe -DMINGW_STDTHREADS_GENERATED_STDHEADERS #CMakeFiles/test.dir/includes_CXX.rsp -std=gnu++14 -o CMakeFiles\test.dir\test.cpp.obj -c C:\Users\luigi\Desktop\test\test.cpp
In file included from C:/Users/luigi/Desktop/test/mingw-std-threads-master/mingw.condition_variable.h:53,
from C:/Users/luigi/Desktop/test/build/mingw-std-threads-master/cmake_stdheaders_generator/cmake_stdheaders_generator/condition_variable:10,
from C:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/shared_mutex:37,
from C:/Users/luigi/Desktop/test/build/mingw-std-threads-master/cmake_stdheaders_generator/cmake_stdheaders_generator/shared_mutex:9,
from C:\Users\luigi\Desktop\test\test.cpp:1:
C:/Users/luigi/Desktop/test/mingw-std-threads-master/mingw.shared_mutex.h:306:12: error: 'std::shared_lock' has not been declared
using std::shared_lock;
^~~~~~~~~~~
C:/Users/luigi/Desktop/test/mingw-std-threads-master/mingw.shared_mutex.h:492:24: error: 'mingw_stdthread::shared_lock' has not been declared
using mingw_stdthread::shared_lock;
^~~~~~~~~~~
mingw32-make.exe[2]: *** [CMakeFiles\test.dir\build.make:82: CMakeFiles/test.dir/test.cpp.obj] Error 1
mingw32-make.exe[2]: Leaving directory 'C:/Users/luigi/Desktop/test/build'
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:132: CMakeFiles/test.dir/all] Error 2
mingw32-make.exe[1]: Leaving directory 'C:/Users/luigi/Desktop/test/build'
mingw32-make.exe: *** [Makefile:148: all] Error 2
PS C:\Users\luigi\Desktop\test>
These are the versions of the tools I'm using:
Windows 10 Pro x64
MinGW-w64 8.1.0
CMake 3.18.3 (using 3.9 for the configuration)
mingw-std-threads 1.0.0
Thanks for helping!

CMake does not accept MinGW compilers

I just started using CMake so I tried to build a simple hello-world project and got an error.
There is a main.cpp file, which contains this:
int main()
{
return 0;
}
And a CMakeLists.txt, which contains this:
cmake_minimum_required(VERSION "3.18.0")
project("test")
add_executable("${PROJECT_NAME}" "main.cpp")
install(TARGETS "${PROJECT_NAME}" DESTINATION bin)
install(FILES "main.cpp" DESTINATION src)
There also is a Build directory. I build the project from this directory with the following command:
cmake ..
What I eventually get is:
-- The C compiler identification is GNU 9.2.0
-- The CXX compiler identification is GNU 9.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
-- Check for working C compiler: C:/MinGW/bin/gcc.exe - broken
CMake Error at C:/CMake/share/cmake-3.18/Modules/CMakeTestCCompiler.cmake:66 (message):
The C compiler
"C:/MinGW/bin/gcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Projects/trash/checking_out_cmake/Build/CMakeFiles/CMakeTmp
Run Build Command(s):C:/PROGRA~2/GnuWin32/bin/make.exe cmTC_a48fd/fast && C:/PROGRA~2/GnuWin32/bin/make.exe -f CMakeFiles/cmTC_a48fd.dir/build.make CMakeFiles/cmTC_a48fd.dir/build
make.exe[1]: Entering directory `C:/Projects/trash/checking_out_cmake/Build/CMakeFiles/CMakeTmp'
The system cannot find the path specified.
make.exe[1]: *** [CMakeFiles/cmTC_a48fd.dir/testCCompiler.c.obj] Error 1
make.exe[1]: Leaving directory `C:/Projects/trash/checking_out_cmake/Build/CMakeFiles/CMakeTmp'
make.exe: *** [cmTC_a48fd/fast] Error 2
I have got CLion and it works just fine, so I presume this is MinGW compilers what causes the problem.
I have also tried to reinstall the compilers but the error remains.
Be sure not to use non-Latin characters in the absolute path to your working directory. In my case it was Cyrillic "C" as the name of folder.

How do I cross-compile from Linux targeting Windows using cmake?

I am currently attempting to cross compile targeting Windows using cmake in Linux Subsystem for Windows Ubuntu. I am compiling form Linux because I want to be able to support multiple platforms.
I am unsure how to make this work, and have no preference of compiler.
See the following code and build output for my current attempt.
CMakeLists.txt file
cmake_minimum_required(VERSION 3.7)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/win.toolchain.cmake)
project(environment.exe)
find_package(SDL2 REQUIRED)
include_directories(environment.exe ${SDL2_INCLUDE_DIRS})
# get executable src files
file(GLOB_RECURSE environment.exe_src ${CMAKE_CURRENT_SOURCE_DIR}/src/environment/*.cpp)
# add environment.exe executable
add_executable(environment.exe ${environment.exe_src})
target_link_libraries(environment.exe ${SDL2_LIBRARIES})
# set output dir
set_target_properties(
environment.exe
PROPERTIES
# ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/suite/lib"
# LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/suite/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/environment"
)
win.toolchain.cmake file
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR x64)#i686
set(triple x64-pc-win32)
set(CMAKE_C_COMPILER clang)
set(CMAKE_C_COMPILER_TARGET ${triple})
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_CXX_COMPILER_TARGET ${triple})
BASH output
a#DESKTOP-DCHFQSJ:/mnt/e/d/User/Software Projects/windows-software-environment$ ./build.sh
Checking for make installation.
make is installed.
Checking for cmake installation.
cmake is installed.
Checking for mingw-w64 installation.
mingw-w64 is installed.
Checking for g++-mingw-w64 installation.
g++-mingw-w64 is installed.
Checking for libsdl2-dev installation.
libsdl2-dev is installed.
./build.sh: line 30: cd: ./build: No such file or directory
Running cmake on './build'
-- The C compiler identification is Clang 6.0.0
-- The CXX compiler identification is Clang 6.0.0
-- Check for working C compiler: /usr/bin/clang
-- Check for working C compiler: /usr/bin/clang -- broken
CMake Error at /usr/share/cmake-3.10/Modules/CMakeTestCCompiler.cmake:52 (message):
The C compiler
"/usr/bin/clang"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /mnt/e/d/User/Software Projects/windows-software-environment/build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_8a6e7/fast"
/usr/bin/make -f CMakeFiles/cmTC_8a6e7.dir/build.make CMakeFiles/cmTC_8a6e7.dir/build
make[1]: Entering directory '/mnt/e/d/User/Software Projects/windows-software-environment/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_8a6e7.dir/testCCompiler.c.obj
/usr/bin/clang --target=x64-pc-win32 -o CMakeFiles/cmTC_8a6e7.dir/testCCompiler.c.obj -c "/mnt/e/d/User/Software Projects/windows-software-environment/build/CMakeFiles/CMakeTmp/testCCompiler.c"
error: unknown target triple 'x64-pc-windows-msvc19.11.0', please use -triple or -arch
CMakeFiles/cmTC_8a6e7.dir/build.make:65: recipe for target 'CMakeFiles/cmTC_8a6e7.dir/testCCompiler.c.obj' failed
make[1]: *** [CMakeFiles/cmTC_8a6e7.dir/testCCompiler.c.obj] Error 1
make[1]: Leaving directory '/mnt/e/d/User/Software Projects/windows-software-environment/build/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_8a6e7/fast' failed
make: *** [cmTC_8a6e7/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:19 (project)
-- Configuring incomplete, errors occurred!
See also "/mnt/e/d/User/Software Projects/windows-software-environment/build/CMakeFiles/CMakeOutput.log".
See also "/mnt/e/d/User/Software Projects/windows-software-environment/build/CMakeFiles/CMakeError.log".

Error building program with MySQL Connector C++

I have the following compile time error I cannot find the reason of:
fatal error: mysql_connection.h: No such file or directory
I am using cmake, and these are the CMakeLists.txt files:
# Top level CMakeLists.txt - MyProg
cmake_minimum_required (VERSION 2.6)
set (PROJECT_NAME "MyProg")
### Out-of-tree directories
set (UTILITIES_DIR "~/utilities")
### Configure header file to pass CMake's settings to the source code
configure_file (
"Config.h.in"
"${PROJECT_SOURCE_DIR}/Config.h"
)
add_subdirectory (src "${CMAKE_CURRENT_BINARY_DIR}/obj")
add_subdirectory (${UTILITIES_DIR} "${CMAKE_CURRENT_BINARY_DIR}/obj/external/utilities")
and
# Source level CMakeLists.txt - MyProg/src
### MySQL Connector/C++ ###
set (MYSQLCONNECTORCPP_ROOT_DIR "~/3rdParty/mysql-connector-c++-1.1.0")
### Include paths ###
include_directories (${CMAKE_CURRENT_SOURCE_DIR})
include_directories (${UTILITIES_DIR})
include_directories (${MYSQLCONNECTORCPP_ROOT_DIR})
include_directories (/usr/local/include)
link_directories (/usr/local/lib)
link_directories (${MYSQLCONNECTORCPP_ROOT_DIR}/driver)
link_directories (/usr/lib64/mysql/)
link_directories (/usr/lib64/)
link_directories (/usr/local/mysql/lib/)
add_executable (myprog
entrypoint.cpp
MyProg.cpp
MyProg_test.cpp
${UTILITIES_DIR}/DBInterface.cpp
)
target_link_libraries (myprog mysqlcppconn-static mysqlclient)
This is the output from cmake (out of source build):
> cmake ../MyProg/
-- The C compiler identification is GNU 4.7.1
-- The CXX compiler identification is GNU 4.7.1
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- 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
-- Generating done
-- Build files have been written to: ~/MyProg_prj/Debug
And this is the fatal error I get from make:
> make
Scanning dependencies of target myprog
[ 8%] Building CXX object obj/CMakeFiles/myprog.dir/entrypoint.cpp.o
In file included from ~/MyProg_prj/MyProg/src/entrypoint.cpp:18:0:
~/utilities/DBInterface.hpp:18:30: fatal error: mysql_connection.h: No such file or directory
compilation terminated.
make[2]: *** [obj/CMakeFiles/myprog.dir/entrypoint.cpp.o] Error 1
make[1]: *** [obj/CMakeFiles/myprog.dir/all] Error 2
make: *** [all] Error 2
The mysql_connection.h file is in the directory specified in the CMakeLists.txt file.
This problem happened after I upgraded Linux (before it worked correctly), but this should not be the reason. The PATH should contain everything needed.
Thank you.
Platform: Linux (OpenSuse), GCC 4.7.1, cmake, MySQL Connector C++ 1.1.0
You are most likely missing the 'libmysqlcppconn-dev' library. Once installed, you shouldn't be seeing this error.
Before updating the system, in the source code I included the MySQL header like this:
#include <mysql_connection.h>
Now I have to specify the subdirectory:
#include <driver/mysql_connection.h>
Something must have changed in how the paths are set...

Link MySQL Librarys in CMake

I'm starting to learn how to use CMake, but I have had several problems with the linking libraries. Now my problem is with MySQL (C). As there is by default the FindMySQL.cmake I included one that I found, however, it does not solve because my libraries are in separate folders within the project.
My project structure:
/
/ CMakeLists.txt
/include
/include/mysql (...)
/lib (libmysql.lib, mysqlclient.lib, libmysql.dll)
/src (main.cpp)
/src/login (login.cpp, login.h)
/build (Build Directory of CMake)
Sorry for the lack of organization, but is that a long time since I have this problem and I'm using "angry."
My current CMakeLists:
# eGest - Product Sales by Console
# Copyright (C) 2011 Bruno Alano
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# --------------------------------------------------------------------------
# CMake - Build System
# Minium CMake Version
cmake_minimum_required (VERSION 2.6)
# Project Name
project (egest)
# Add MySQL
# find_package(MySQL REQUIRED)
include_directories(include)
set(CMAKE_LIBRARY_PATH /lib)
set(LIBS ${LIBS} mysql)
# Include Directory
include_directories(src)
# Link the MySQL
# Add Sources
add_executable(test src/egest.cpp src/login/login.cpp)
target_link_libraries(test ${LIBS})
But if I use that, return this error:
C:\Users\ALANO\eGest\build>cmake .. -G "MinGW Makefiles"
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
-- Check for working C compiler: C:/MinGW/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/ALANO/eGest/build
C:\Users\ALANO\eGest\build>make
Scanning dependencies of target test
[ 50%] Building CXX object CMakeFiles/test.dir/src/egest.cpp.obj
[100%] Building CXX object CMakeFiles/test.dir/src/login/login.cpp.obj
Linking CXX executable test.exe
c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../mingw32/bin/ld.exe: cannot fin
d -lmysql
collect2: ld returned 1 exit status
make[2]: *** [test.exe] Error 1
make[1]: *** [CMakeFiles/test.dir/all] Error 2
make: *** [all] Error 2
Thanks, Bruno Alano.
CMAKE_LIBRARY_PATH is where CMake puts the libraries it builds, not where it looks for existing libraries.
Try adding link_directories("${PROJECT_SOURCE_DIR}/lib") before add_executable.
Then do make VERBOSE=1 to see what compiler options are being passed--hopefully one of them will be the -L (library search path) you just added.