simon_b64
simon_b64

Reputation: 13

Linkingoption for mariadb connector c

Sooo, I am writing a C++ application to receive Data from a Socket and save it into a MariaDB database.

I included the MariaDB connector c library from the libmariadb3 package and it worked without a problem.

When compiling the program I had to add the linking option -l mysqlclient.

Compile command would be:

g++ main.cpp -o output -l mysqlclient

So my question is why do I have to add this linking option and how can I work around it so that I don't have to add this option?

(This is an example compile command. In reality I am compiling with cmake and I have compiled the mariadb connector c library myself. The linker option in cmake would be target_link_options(${PROJECT_NAME} PUBLIC -lmysqlclient))

Upvotes: 0

Views: 669

Answers (1)

rustyx
rustyx

Reputation: 85541

There is no workaround, you need to link with the libraries you want to use.

In CMake, target_link_libraries simplifies this and adds the needed include paths and libs when compiling/linking.

Upvotes: 1

Related Questions