Bonjour,

Je rencontre un problème dans l'utilisation du framework unit_test de boost avec autoconf et automake.

J'ai déjà posté sur le forum dédié à boost, mais il semble que la fréquentation y est limitée, et ce problème n'étant pas uniquement lié à boost, je me permets de reposter ici.

La structure du projet se présente en gros de la façon suivante:
./include/com_i_foo.h
./include/com_foo.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
...
class FooSingleton {
protected:
FooSingleton() {}
private:
FooSingleton* _instance;
public:
virtual ~FooSingleton() {}
static FooSingleton* getInstance();
};
 
class FooFoo {
public:
FooFoo() {}
virtual uint32_t getSomeInt();
virtual ~FooFoo() {}
};
typedef boost::shared_ptr<FooFoo> FooFooPtr_t;
...
./include/com_api.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
#include "com_foo.h"
./include/Makefile.am
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
 
include_HEADERS = \
        com_i_foo.h \
        com_foo.h \
        com_api.h \
        $(NULL)
./src/com_foo.cpp
./src/Makefile.am
./test/Makefile.am
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
PLATEFORM=LINUX64
DEBUG_OPTIONS = -g
DEFINE_OPTIONS=-D${PLATEFORM} -DBOOST_ENABLE_ASSERT_HANDLER
OPTIONS = -Wall -Werror -O2 $(DEBUG_OPTIONS) $(DEFINE_OPTIONS)
 
BOOST_LIBS = -lboost_unit_test_framework -lboost_locale -lboost_filesystem -lboost_system -lboost_thread
 
COMMON_CXXFLAGS= ${OPTIONS} -I$(top_srcdir)/include -I$(top_srcdir)/src
AM_LDFLAGS=
ACLOCAL_AMFLAGS = -I ${top_builddir}/m4
 
check_PROGRAMS = ut_com_api
 
ut_com_api_SOURCES = \
        ut_com_api.cpp \
        $(NULL)
ut_com_api_CXXFLAGS = ${COMMON_CXXFLAGS}
ut_com_api_LDFLAGS = -rdynamic
ut_com_api_LDADD = ${BOOST_LIBS} $(top_builddir)/src/libcom_api.la
./test/ut_com_api.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
#define BOOST_LIB_DIAGNOSTIC
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE "Common API Unit tests"
 
#include <boost/test/unit_test.hpp>
 
#include "com_api.h"
 
using namespace boost::unit_test;
 
BOOST_AUTO_TEST_SUITE(com_api)
 
BOOST_AUTO_TEST_CASE(FooFooTest) {
FooFooPtr_t myFoo(new FooFoo());
BOOST_CHECK(myFoo.getSomeInt() == 2);
}
 
BOOST_AUTO_TEST_CASE(FooSingletonTest) {
FooSingleton* myFoo = FooSingleton::getInstance();
BOOST_CHECK(myFoo != NULL);
}
 
BOOST_AUTO_TEST_SUITE_END()
./Makefile.am
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
 
SUBDIRS = include src test
#dist_doc_DATA = README
ACLOCAL_AMFLAGS = -I m4
./configure.ac
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
AC_INIT([com_api], [1.0], [bug@foo.foo])
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_PROG_LIBTOOL
AC_PROG_CXX
AC_LANG_PUSH(C++)
AX_BOOST_BASE([1.53], ,[AC_MSG_ERROR([You need boost library])])
AX_BOOST_PROGRAM_OPTIONS
AX_BOOST_DATE_TIME
AC_CHECK_HEADER([boost/shared_ptr.hpp], , [AC_MSG_ERROR([You need boost library])])
AC_LANG_POP(C++)
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([
Makefile
include/Makefile
src/Makefile
test/Makefile
])
AC_OUTPUT
Lorsque je builde la DLL (.so sous linux), ça fonctionne parfaitement, mais lorsque je tente de builder le check_PROGRAM, le linker me retourne des undefined reference:
undefined reference to FooSingleton::_instance
undefined reference to boost::assertion_failed(char const*, char const*, char const*, long)

Pour le FooSingleton je ne comprends pas car je link bien avec le .la.

Pour boost, j'imagine qu'il me manque un -lboost_xxxx mais je ne comprends pas non-plus pourquoi je suis obligé de spécifier les libs boost au linker pour le check_PROGRAM, alors que ça fonctionne parfaitement avec la lib...

J'ai cherché un peu partout sans succès et je suis un peu à court d'idées, merci d'avance pour votre aide!