Thread: cant link mysql client libraries to a c file.

  1. #1
    Registered User
    Join Date
    Sep 2017
    Posts
    1

    cant link mysql client libraries to a c file.

    Hi, I am following a tutorial for MySQL C API Programming;
    MySQL C API programming tutorial
    My main.c looks like this:
    Code:
    
    #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.
    Code:
    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.

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Run this on the command line of your computer.

    Code:
    mysql_config --cflags --libs
    Then figure out how to add the information returned to CLion.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can't link openssl static libraries
    By Avega768 in forum C++ Programming
    Replies: 3
    Last Post: 02-27-2012, 05:19 AM
  2. dynamic link libraries
    By Coga1900 in forum C++ Programming
    Replies: 19
    Last Post: 11-13-2011, 07:39 AM
  3. How to link libraries to MinGW?
    By ahernan17 in forum C Programming
    Replies: 10
    Last Post: 10-23-2010, 12:35 PM
  4. MySQL libraries
    By csonx_p in forum C++ Programming
    Replies: 6
    Last Post: 10-02-2008, 02:23 AM
  5. Static link libraries on other computers
    By bennyandthejets in forum C++ Programming
    Replies: 6
    Last Post: 11-05-2003, 06:01 PM

Tags for this Thread