FreeBSD, MySQL 5.1 and C++

Please, rotin a working example on C++ demonstrating work with MYSQL Server 5.1.

Code:
#include </usr/local/include/mysql/mysql.h>
#include <iostream>
using namespace std;
 
MYSQL mysql;
//-------------------------------------------------------------------------------
void exiterr(int exitcode);
//===============================================================================
int main(){
 
        mysql_init(&mysql);             
        if(!mysql_real_connect(&mysql, "localhost", "root", "pass", "test", 3036, NULL, 0))
                exiterr(1);
        mysql_close(&mysql);
        return 0;
}
//===============================================================================
void exiterr(int exitcode){
        std::cout << STDCALL::mysql_error(&mysql)<<"\n";
        exit(exitcode);
}

I can not compile ...

Code:
/usr/home/Admin/projects/alexaupload/build> make
Linking CXX executable alexaupload
CMakeFiles/alexaupload.dir/main.cpp.o(.text+0x1ae): In function `exiterr(int)':
/usr/home/Admin/projects/alexaupload/main.cpp:20: undefined reference to `mysql_error'
CMakeFiles/alexaupload.dir/main.cpp.o(.text+0x1f9): In function `main':
/usr/home/Admin/projects/alexaupload/main.cpp:11: undefined reference to `mysql_init'
CMakeFiles/alexaupload.dir/main.cpp.o(.text+0x23d):/usr/home/Admin/projects/alexaupload/main.cpp:12: undefined reference to `mysql_real_connect'
CMakeFiles/alexaupload.dir/main.cpp.o(.text+0x25e):/usr/home/Admin/projects/alexaupload/main.cpp:14: undefined reference to `mysql_close'
*** Error code 1

Stop in /usr/home/Admin/projects/alexaupload/build.
*** Error code 1

Stop in /usr/home/Admin/projects/alexaupload/build.
*** Error code 1

Stop in /usr/home/Admin/projects/alexaupload/build.
*** Ошибка ***
 
You might also try going under the covers of make to see at which step it breaks.
Code:
c++ -v -E main.cpp -o main
c++ -v -S main.cpp -o main
etc
If it doesn't link, maybe there's a library you need to specify.
 
I ask to excuse. I will specify the problem. Do I use Kdevelop 4. how to influence this environment that began to work?
 
I already a bit understood that takes place ...

1. I, in Kdevelop use Cmake.

2. In Kdevelop is a function that, and made me make mistakes. Specifying the path to the header files, Kdevelop not connect them to the project to compile.

If I understand correctly, I need to configure CMakeLists.txt

Here is the contents of this file.

Code:
project(alexa)

add_executable(alexa main.cpp)
 
qsecofr said:
You might also try going under the covers of make to see at which step it breaks.
Code:
c++ -v -E main.cpp -o main
c++ -v -S main.cpp -o main
etc
If it doesn't link, maybe there's a library you need to specify.

Thank you enormous. Understood due to you. :stud
 
If you solve it, please mark the post as such, and let us know how you solved it. It may help someone else in the future.
 
Back
Top