Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8065637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:43:51+00:00 2026-06-05T11:43:51+00:00

I am trying to compile my program on my new server, but it’s not

  • 0

I am trying to compile my program on my new server, but it’s not working for me at the moment.

Error log is:

rasmus@web01:~/c++$ make test
g++ `mysql_config --cflags --libs` main.cpp logger.cpp cpulogger.cpp -o test
/tmp/ccPaMZUy.o: In function `CPULogger':
/home/rasmus/c++/cpulogger.cpp:7: undefined reference to `mysql_init'
/home/rasmus/c++/cpulogger.cpp:8: undefined reference to `mysql_real_connect'
/home/rasmus/c++/cpulogger.cpp:10: undefined reference to `mysql_get_client_info'
/tmp/ccPaMZUy.o: In function `~CPULogger':
/home/rasmus/c++/cpulogger.cpp:16: undefined reference to `mysql_close'
collect2: ld returned 1 exit status
make: *** [all] Error 1

As you can see I am compiling against MySQL – I have checked that mysql.h is present in include paths.

What am I missing?

cpulogger.cpp has #include “cpulogger.h” at the top, then cpulogger.h has this:

#include <iostream>
#include <fstream>
#include <mysql/mysql.h>

The compiler does not complain about missing mysql/mysql.h, so that part must work?

Output of mysql_config:

rasmus@web01:~/c++$ mysql_config --cflags --libs
-I/usr/include/mysql -DBIG_JOINS=1  -fno-strict-aliasing  -g
-L/usr/lib -lmysqlclient -lpthread -lz -lm -lrt -ldl

Makefile:

all:
    g++ `mysql_config --cflags --libs` main.cpp logger.cpp cpulogger.cpp -o test


test: all
    ./test

It’s a fresh Ubuntu server installation with a mysql-server install on it.

[solved]:

Putting linker libraries at the end of the compiler commands works.

all:
    g++ main.cpp logger.cpp cpulogger.cpp -o test `mysql_config --cflags --libs`

See answer below for explanation.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T11:43:53+00:00Added an answer on June 5, 2026 at 11:43 am

    The order of arguments to the linker is significant. Use mysql-config after listing the files that need it. The linker will see that cpulogger.o needs mysql_init and look in libraries listed after it for the symbol. If the libraries were listed earlier in the arguments they won’t be searched again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

when I'm trying to compile my c program it gives me this error warning:
I'm new to gcc, and trying to compile a c++ program which includes mysql.h
Perhaps I'm being over-ambitious, but I'm trying to write a server program which can
I am getting the following error when trying to compile my program. '(' or
I keep getting an error when trying to compile my program, i'm having issues
I'm new to Qt , and trying to compile and run this Qt program
I am getting a heap corruption error when trying to compile my program. The
I am trying to compile my C program in Ubuntu 9.10 (gcc 4.4.1). I
I'm trying to compile this simple program to start learning how to use timers:
I'm trying to compile the following program: #include<functional> #include<iostream> int main(int argc, char* argv[],

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.