Reputation: 643
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.
Upvotes: 3
Views: 5562
Reputation: 249394
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.
Upvotes: 4