Thread: autoconf and boost problem

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    222

    autoconf and boost problem

    hi

    second problem of the day. I am compiling a program using autotools. however, in the comilation process the command that gets executed is:

    g++ -std=c++0x -O2 -lboost_program_options -lboost_filesystem -lboost_system -lboost_regex -o Test Test-Test.o

    which gives me the error stating undefined reference to boost:rogram_options ...

    the reason is my boost libs are called before -o Test Test-Test.o if I do :

    g++ -std=c++0x -O2 -o Test Test-Test.o -lboost_program_options -lboost_filesystem -lboost_system -lboost_regex

    everything compiles with no problem.

    The question is how to switch this and where exactly. Note the automake and autoconf is used here for compiling

    thnx

  2. #2
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    Search the library named library when linking. (The second alternative with the library as a separate argument is only for POSIX compliance and is not recommended.)
    It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, ‘foo.o -lz bar.o’ searches library ‘z’ after file foo.o but before bar.o. If bar.o refers to functions in ‘z’, those functions may not be loaded.


    The linker searches a standard list of directories for the library, which is actually a file named liblibrary.a. The linker then uses this file as if it had been specified precisely by name.


    The directories searched include several standard system directories plus any that you specify with -L.


    Normally the files found this way are library files—archive files whose members are object files. The linker handles an archive file by scanning through it for members which define symbols that have so far been referenced but not defined. But if the file that is found is an ordinary object file, it is linked in the usual fashion. The only difference between using an -l option and specifying a file name is that -l surrounds library with ‘lib’ and ‘.a’ and searches several directories.
    tl;dr Its easier for the compiler that way; at least gcc developers think its easier.

    I dunno whether you can change this behaviour though, can't you just change you build scripts?

  3. #3
    Registered User
    Join Date
    Jan 2011
    Posts
    222
    well that is tthe point I don't know how since I am using Makefile.am script that looks like this :

    Code:
    #where is binary produced
    bin_PROGRAMS = Test
    Test_SOURCES = Test.cpp
    AM_CPPFLAGS = -I$(top_srcdir)/src/include 
    AM_LDFLAGS = -lboost_program_options -lboost_filesystem -lboost_system -lboost_regex
    SeqTest_CXXFLAGS=-std=c++0x
    I trully don't know how to set the order

    UPDATE:
    Please don't hate. It is not my fault I was accidently dropped on the head as a bybe :

    From the Automake manual:

    PROG_LDADD is inappropriate for passing program-specific linker flags (except for -l, -L, -dlopen and -dlpreopen). So, use the PROG_LDFLAGS variable for this purpose.
    Last edited by baxy; 03-16-2015 at 10:34 AM. Reason: update

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I think this is more suitable for techtalk next time since this is about tools and not the C++ language itself.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting Automake/Autoconf to compile C
    By Jamie_Edwards in forum Linux Programming
    Replies: 4
    Last Post: 07-13-2012, 12:48 PM
  2. autoconf endian test
    By Scramble in forum Linux Programming
    Replies: 1
    Last Post: 03-11-2011, 08:23 AM
  3. Autoconf help
    By tpe in forum Linux Programming
    Replies: 6
    Last Post: 12-02-2010, 02:32 PM
  4. Error Using Autoconf in Cygwin
    By Tonto in forum Tech Board
    Replies: 13
    Last Post: 09-22-2007, 04:14 PM
  5. AUTOCONF macro + gcc -Wunreachable-code = NOWORK
    By tomsky in forum Linux Programming
    Replies: 2
    Last Post: 10-11-2005, 11:37 AM