There was a task to write some code that will do something with the Mysql database. Difficulty in setting options for g ++.

At the moment, the options are:

g++ -I/usr/include/mysql++ -I/usr/include/mysql 

Ways are right, but the project does not want to assemble normally.

----------Build Started-------- /bin/sh -c '"make" -j 2 -f "MHC_wsp.mk"' ----------Building project:[ Myhobby - Debug ]---------- make[1]: Вход в каталог '/home/kost/.codelite/MHC' g++ -c "/home/kost/.codelite/MHC/main.cpp" -g -I/usr/include/mysql++ -I/usr/include/mysql -o ./Debug/main.o "-I." "-I." /home/kost/.codelite/MHC/main.cpp:1:19: warning: extra tokens at end of #include directive /home/kost/.codelite/MHC/main.cpp:2:19: warning: extra tokens at end of #include directive /home/kost/.codelite/MHC/main.cpp:3:20: warning: extra tokens at end of #include directive /home/kost/.codelite/MHC/main.cpp: In function 'int main()': /home/kost/.codelite/MHC/main.cpp:63:19: warning: deprecated conversion from string constant to 'char*' /home/kost/.codelite/MHC/main.cpp:64:17: warning: deprecated conversion from string constant to 'char*' /home/kost/.codelite/MHC/main.cpp:65:21: warning: deprecated conversion from string constant to 'char*' /home/kost/.codelite/MHC/main.cpp:66:21: warning: deprecated conversion from string constant to 'char*' /home/kost/.codelite/MHC/main.cpp:72:56: warning: deprecated conversion from string constant to 'char*' g++ -o ./Debug/Myhobby ./Debug/main.o "-L." ./Debug/main.o: In function 'mysql_connection_setup(connection_details)': /home/kost/.codelite/MHC/main.cpp:24: undefined reference to 'mysql_init' /home/kost/.codelite/MHC/main.cpp:27: undefined reference to 'mysql_real_connect' /home/kost/.codelite/MHC/main.cpp:28: undefined reference to 'mysql_error' ./Debug/main.o: In function 'mysql_perform_query(st_mysql*, char*)': /home/kost/.codelite/MHC/main.cpp:41: undefined reference to 'mysql_query' /home/kost/.codelite/MHC/main.cpp:43: undefined reference to 'mysql_error' /home/kost/.codelite/MHC/main.cpp:47: undefined reference to 'mysql_use_result' ./Debug/main.o: In function 'main': /home/kost/.codelite/MHC/main.cpp:79: undefined reference to 'mysql_fetch_row' /home/kost/.codelite/MHC/main.cpp:83: undefined reference to 'mysql_free_result' /home/kost/.codelite/MHC/main.cpp:85: undefined reference to 'mysql_close' collect2: ld returned 1 exit status make[1]: *** [Debug/Myhobby] Ошибка 1 make[1]: Выход из каталога '/home/kost/.codelite/MHC' make: *** [All] Ошибка 2 ----------Build Ended---------- 9 errors, 8 warnings

While for me it is completely incomprehensible why.

PS rights to /usr/include/mysql (mysql++) = 777
PPS - Actually, the problem is that the compiler does not see links to the necessary objects: (

    1 answer 1

    The fact is that in the headers (* .h) there are only function declarations, i.e. their interface. The compiled code of these functions is in the library. Therefore, when linking, you need to add the library libmysql ++, in which the missing characters are defined. The line of copying when linking will look something like this:

     g++ -o ./Debug/Myhobby ./Debug/main.o -lmysqlpp 

    This means that the compiler must link the dynamic library libmysqlpp.so, which is located either in one of the directories specified explicitly (-L [directory name]) or in the default system directory with installed libraries (usually / usr / lib).

    PS : Do not explicitly specify the -I options "/ usr / include / ...". The compiler itself searches for includes in the place where the installed libraries store their headers (usually / usr / include). In the include program, you need to write something like this:

     #include <mysql++/query.h> 

    PPS : In vain you have 777 permissions on / usr / include / mysql ++ - ordinary users should not have permission to change this directory.