Trouble compiling with gcc (mariadb/mysql)

Hi,

I just came over to FreeBSD from CentOS, so I'm still catching up with the basics. I'm having trouble with compiling using gcc in regards to mysql. I have compiled this same source file on CentOS with gcc with the following command:

Code:
"sudo gcc -std=gnu11 -Wall -lm -o /path/compiled.cgi /path/source.c -lmysqlclient "
now I'm using it without 'sudo' (by just becoming root using 'su')

and inside the file I have:
Code:
#include <mysql/mysql.h>

I'm getting a error:

Code:
/usr/local/bin/ld: cannot find -lmysqlclient
collect2: error: ld returned 1 exit status

on doing "find /usr -iname 'mysql' , I get:

Code:
/usr/local/share/mysql
/usr/local/include/mysql
/usr/local/include/mysql/server/mysql
/usr/local/include/mysql/mysql
/usr/local/lib/mysql
/usr/local/bin/mysql

I have both mariadb103-server and client installed. I suppose I don't need connector C? I have also tried:

Code:
-I/usr/local/mysql/include
-L/usr/local/mysql/lib -lmysqlclient

Thank you for your help in advance.
 
What are you trying to build? Not everything compiles cleanly on FreeBSD, this is why many ports contain patches to apply specific changes.

Anyway, it's the client which contains the header files and libraries, check using pkg info -lx mariadb103-client | less. After that you can point whatever you're compiling into the right direction(s).

Still, /usr/local/mysql seems off, have you ever tried looking there yourself? /usr/local/lib/mysql sounds more likely (note: I don't use mariadb, but this is how MySQL would respond).
 
I'm not building any complex software. Its a basic login script only. I'm not sure what you are suggesting here:

1. "pkg info -lx mariadb103-client | less" <--- to check for what?
2. Look for what in /usr/local/lib/mysql ?

yes MariaDB is identical to MySQL in my knowledge.
 
Update. I'm able to compile using:
Code:
gcc -std=gnu11 -Wall -lm -o /path/Test.cgi /path/Test.c -L/usr/local/lib/mysql -lmysqlclient
(yay!)

1. I'm thinking, that earlier the compiler couldn't find mysql libs and headers? By giving it the right path to them, it works now.
2. I'm still clueless as to why, it requires

Code:
#include <mysql/mysql.h>
instead of just
Code:
 #include <mysql.h>
 
2. I'm still clueless as to why, it requires

Code:
#include <mysql/mysql.h>
instead of just
Code:
 #include <mysql.h>
Simple: a default include directory is /usr/local/include. That directory doesn't contain mysql.h but it does have a subdirectory mysql which contains the right file. So you're simply telling the system to look in that subdirectory.
 
But I used : -L/usr/local/lib/mysql on command line
And their is no further mysql sub-directory after that. But it still requires and works with mysql/mysql.h
 
But I used : -L/usr/local/lib/mysql on command line
And their is no further mysql sub-directory after that. But it still requires and works with mysql/mysql.h

"-L" stands for Libraries link path, where to find additional libraries.
if you wand to add "includes path" , where to find files included with "#include <somefile.h>", use "-I".

david:~>cat mysql.c
#include <stdio.h>
#include <mysql.h>

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

david:~>cc mysql.c -I/usr/local/include/mysql -lmysqlclient -L/usr/local/lib/mysql
david:~>./a.out
mysql client version: 5.6.41
 
DavidMarec
so in essence, how does that explain the difference between "mysql/mysql.h" working and "mysql.h" not working?

Have a look to shelLuser' answer.

That means that /usr/local/include is somehow defined as a default path for include files, within the toolchain you are using.
This is not the case by default on a fresh installed FreeBSD, however (clang).


You should start using a MakeFile; see the porters handbook for details about dependencies; or ask pkg-config manually.

To followup on my previous message, "-I" is required by the compiler as "-L/l" is required by the linker. Both jobs are different, despite they are performed by the same tool.
 
Back
Top