undefined reference to `main'

F

fdm

I am building a boost unit-test application on Ubuntu 9.04, the below code
is the content of unit_test_text_file_reader.cpp:

#define BOOST_AUTO_TEST_MAIN
#include <boost/test/auto_unit_test.hpp>
// Boost Test declaration and Checking macros
#include <boost/test/unit_test_suite.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/test/floating_point_comparison.hpp>

BOOST_AUTO_TEST_SUITE(text_file_reader);
BOOST_AUTO_TEST_SUITE();
BOOST_AUTO_TEST_CASE(text_file_reader)
{

BOOST_CHECK_EQUAL(2,2);

}

BOOST_AUTO_TEST_SUITE_END();

BOOST_AUTO_TEST_CASE(my_always_fail_test_case)

{

BOOST_CHECK(false);

}

BOOST_AUTO_TEST_SUITE_END();

But when I run make I get:

Scanning dependencies of target unit_test_text_file_reader
[100%] Building CXX object
revised/text_file_reader/CMakeFiles/unit_test_text_file_reader.dir/src/unit_test_text_file_reader.cpp.o
Linking CXX executable unit_test_text_file_reader
/usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../lib/crt1.o: In function
`_start':
/build/buildd/glibc-2.9/csu/../sysdeps/x86_64/elf/start.S:109: undefined
reference to `main'
CMakeFiles/unit_test_text_file_reader.dir/src/unit_test_text_file_reader.cpp.o:
In function `global constructors keyed to _Z20init_unit_test_suiteiPPc':


Especially these lines:
/usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../lib/crt1.o: In function
`_start':
/build/buildd/glibc-2.9/csu/../sysdeps/x86_64/elf/start.S:109: undefined
reference to `main'

seems critical. I have build plenty of these boost unit-test on windows
vista 64 without specifying a main function, but for some reason this is not
possible in Ubuntu, any ideas?
 
M

Maxim Yegorushkin

I am building a boost unit-test application on Ubuntu 9.04, the below
code is the content of unit_test_text_file_reader.cpp:

#define BOOST_AUTO_TEST_MAIN
#include <boost/test/auto_unit_test.hpp>
[]

Linking CXX executable unit_test_text_file_reader
/usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../lib/crt1.o: In function
`_start':
/build/buildd/glibc-2.9/csu/../sysdeps/x86_64/elf/start.S:109: undefined
reference to `main'
CMakeFiles/unit_test_text_file_reader.dir/src/unit_test_text_file_reader.cpp.o:
In function `global constructors keyed to _Z20init_unit_test_suiteiPPc':


Especially these lines:
/usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../lib/crt1.o: In function
`_start':
/build/buildd/glibc-2.9/csu/../sysdeps/x86_64/elf/start.S:109: undefined
reference to `main'

Try adding -lboost_unit_test_framework to your linker command line.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top