cant link mysql client libraries to a c file.

已回答

Hi, I am following a tutorial for MySQL C API Programming;

http://zetcode.com/db/mysqlc/

My main.c looks like this:

#include <stdio.h>
#include <mysql.h>

int main() {
printf("MySQL client version: %s\n", mysql_get_client_info());
exit(0);
}

I was able to build and run the program on the terminal

gcc main.c -o main `mysql_config --cflags --libs`

However, I want to achieve the same thing in CLion IDE.

My CMakeLists.txt file has the following content.

cmake_minimum_required(VERSION 3.6)
project(dbJob)

set(CMAKE_C_STANDARD 99)

set(SOURCE_FILES main.c)
add_executable(dbJob ${SOURCE_FILES})

include_directories(/usr/include/mysql/)

link_directories(/usr/include/mysql/)

Upon building, the CLion outputs the following:

undefined reference to `mysql_get_client_info'

Can I get some help.

Thanks. 

1

Hi!

Please try to add 

target_link_libraries(dbJob mysqlclient)

into your CMakeLists.txt file. Note, that target_link_libraries() shall be placed after add_executable() command.

1
Avatar
Permanently deleted user

Anna Falevskaya, thank you very much, it worked for me)))))))))))) 

0

请先登录再写评论。