سؤال

I'm not sure if I'm completely missing the point here, but I can't find a place to add linker options in the Eclipse CDT plugin for an Autotools project. I want to link a static library with a -l option I was expecting to find them in a tab with a name like 'linker' after going to

Project -> Properties -> C/C++ Build -> Settings

Where do I get to the linker options?

If I can't do it like this then which config or make file can I edit manually to achieve the same result (linking a static library)

--edit--

I came across a recommendation that I should add this to my configure.ac

PKG_CHECK_MODULES([DEPS], [libavutil >= 6:0.8.10-1 libavformat >= 6:0.8.10-1 libavcodec >= 6:0.8.10-1])

I tried this but this doesn't persuade autotools to tell the linker to link the appropriate libraries. Have I missed something???

--edit 2--

My Makefile.am was the default as generated by the CDT new project wizard for an autotools project.

SUBDIRS=src

The Config.ac file was as per default too...

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

AC_PREREQ(2.59)
AC_INIT(HelloWorld, 1.0)


AC_CANONICAL_SYSTEM
AM_INIT_AUTOMAKE()

AC_PROG_CXX

AC_CONFIG_FILES(Makefile src/Makefile)
AC_OUTPUT

I tried adding in a line to the Config.ac that looked like this:

PKG_CHECK_MODULES([libav], [libavutil >= 6:0.8.10-1 libavformat >= 6:0.8.10-1 libavcodec >= 6:0.8.10-1])

I put this line just after the 'AC_PROG_CXX' line

I then added the following to my Makefile.am...

HelloWorld_CPPFLAGS = $(libav_CFLAGS)
HelloWorld_LDFLAGS= $(libav_LIBS)

The file HelloWorld.cpp is just a quick test that should report the libavformat version

#include <stdio.h>
extern "C" {
    #include <libavformat/avformat.h>
}

int main(void) {
int avVer = avformat_version();
printf("libavformat version number: %d", avVer);
return 0;
}

This is all managed by the eclipse CDT.

هل كانت مفيدة؟

المحلول 2

This article has helped clarify things: http://aquamentus.com/autoconf_tutorial.html

I was putting some things in the wrong places. A separate Makefile.am is used for the program as it is in the src subdirectory. This needed to go in the Configure.ac as sugested before

PKG_CHECK_MODULES([libav], [libavutil >= 6:0.8.10-1 libavformat >= 6:0.8.10-1 libavcodec >= 6:0.8.10-1])

This generates two variables to use in the Makefile.am, these are...

$(libav_CFLAGS)
$(libav_LIBS)

The top level Makefile.am just needs to point to that directory as it did before...

SUBDIRS=src

The linker flags for the program are handled in the src/Makefile.am file with something like the following...

bin_PROGRAMS=HelloWorld
HelloWorld_SOURCES=HelloWorld.cpp
HelloWorld_CPPFLAGS = $(libav_CFLAGS)
HelloWorld_LDFLAGS= $(libav_LIBS)

نصائح أخرى

You need to add the relevant -l flag to AM_LDFLAGS in Makefile.am; e.g.:

AM_LDFLAGS = -l<library name>

It is considered a good idea to add the corresponding code in configure.ac to ensure portability to other systems.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top