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

  • Home
  • SEARCH
  • 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 8930487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:54:12+00:00 2026-06-15T08:54:12+00:00

I have an autotools project that compiles just fine on the Mac, but under

  • 0

I have an autotools project that compiles just fine on the Mac, but under Linux (Ubuntu 12.04.1 LTS) the command lines passed to gcc have the libraries out of order relative to the object files. For example, autotools generates the following command to compile my code, a single file named test.c into a binary named test:

gcc -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -g -O2 -lglib-2.0 -o test test-test.o

This command line fails with:

/home/user/glib-test/test.c:4: undefined reference to `g_malloc`
/home/user/glib-test/test.c:5: undefined reference to `g_free`

However, if I compile from the command line and switch it up so the library reference is after the object files it works just fine:

gcc -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -g -O2 -o test test-test.o -lglib-2.0

The challenge is that I can’t figure out how to force Autotools to generate the command line in the right order. For the sake of clarity, I’ve reproduced the simple test case here. First up is configure.ac:

dnl Process this file with autoconf to produce a configure script.

AC_PREREQ(2.59)
AC_INIT(glib-test, 1.0)

AC_CANONICAL_SYSTEM
AM_INIT_AUTOMAKE()

AC_PROG_CC
AM_PROG_CC_C_O
PKG_CHECK_MODULES(GLIB, glib-2.0 > 2.0)
AC_CONFIG_FILES(Makefile)
AC_OUTPUT

Next is the simple Makefile.am:

CFLAGS=-Wall
bin_PROGRAMS=test
test_CFLAGS=$(GLIB_CFLAGS)
test_LDFLAGS=$(GLIB_LIBS)
test_SOURCES=test.c

Finally, the source code to this minimal test case, test.c:

#include <glib.h>

int main(int argc, char **argv) {
    gchar *foo = g_malloc(100);
    g_free(foo);
    return 0;
}

Compilation is then achieved using the following series of commands:

touch NEWS README AUTHORS ChangeLog
aclocal
autoconf
automake --add-missing
./configure
make

I should be clear, I understand why my code won’t compile, I’m just wondering how to get automake to put the libraries at the end of the command line so gcc will execute and link properly. It should be noted that gcc on Mac OS X Lion doesn’t seem to have this problem.

  • 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-15T08:54:13+00:00Added an answer on June 15, 2026 at 8:54 am

    The solution turned out to be the difference between LDFLAGS and LDADD. In short LDFLAGS is added before the object files on the command line and LDADD is added afterwards. Thus, changing Makefile.am to the following solved the problem:

    CFLAGS=-Wall
    bin_PROGRAMS=test
    test_CFLAGS=$(GLIB_CFLAGS)
    test_LDADD=$(GLIB_LIBS)
    test_SOURCES=test.c
    

    It only took tracking down a GCC developer at work to solve. Also, this example I provided is rather poor because test has a defined meaning in some contexts of autotools.

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

Sidebar

Related Questions

I have a newbie Linux programming question. Suppose I have a project that uses
I have a project that uses autotools. A nice feature of autotools is 'out-of-source'
We have an autotools project that has a mixture of unit and integration tests,
In a project built with GNU Autotools, I have a script that needs to
I have a project using GNU autotools, with a section of Makefile.am that looks
I have a C++ project that uses the GNU Autotools for its build scripts
I have an autotools project. The same tarball on one machine compiles the files
Problem: I have a project which I'm porting from Solaris/Lex/Yacc to Linux/Flex/Bison + Autotools.
I have a project that links to libssl.so and I'm hitting a bug in
I have an existing C++ source code that is built using autotools and i

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.