0

Apologises if the title is a bit convoluted, it's quite difficult to convey my thoughts that way.

Long story short I have a university coursework set this year that needs to me implement some functions, refactor some code and implement Jenkins jobs that automatically trigger upon a commit to a Git repository - using SSH authentication. All this is well and good although I am in the process of writing the Makefile for said project and this is what I have as of right now:

nmea-parser-tests : dataFiles.o nmea-parser.o
    g++ dataFiles.o nmea-parser.o -Wall -o 'nmea-parser-tests'

dataFiles.o : src/dataFiles.cpp headers/dataFiles.h
    g++ -c src/dataFiles.cpp -std=c++17 -Wall -I "headers/nmea" -I "headers"

nmea-parser.o : src/nmea/nmea-parser.cpp headers/nmea/nmea-parser.h
    g++ -c src/nmea/nmea-parser.cpp -std=c++17 -Wall -I "headers/nmea" -I "headers"

clean:
    rm -f nmea-parser-tests
    rm -f *.o

This Makefile works completely fine for my needs when it comes to the 'dataFiles.o' and 'nmea-parser.o' targets for GNU Make to build although when I type 'make nmea-parser-tests' to make the entire BoostUTF automated test program I get the following error:

g++ -c src/dataFiles.cpp -std=c++17 -Wall -I "headers/nmea" -I "headers"
g++ -c src/nmea/nmea-parser.cpp -std=c++17 -Wall -I "headers/nmea" -I "headers"
g++ dataFiles.o nmea-parser.o -Wall -o 'nmea-parser-tests'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
/usr/bin/ld: nmea-parser.o: in function `GPS::NMEA::positionFromSentenceData(GPS::NMEA::SentenceData)':
nmea-parser.cpp:(.text+0x49c): undefined reference to `GPS::Position::Position(double, double, double)'
/usr/bin/ld: nmea-parser.cpp:(.text+0x801): undefined reference to `GPS::Position::Position(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/usr/bin/ld: nmea-parser.cpp:(.text+0xbb0): undefined reference to `GPS::Position::Position(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/usr/bin/ld: nmea-parser.cpp:(.text+0xf76): undefined reference to `GPS::Position::Position(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, char, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
collect2: error: ld returned 1 exit status
make: *** [Makefile:2: nmea-parser-tests] Error 1

As you can see from the first couple of lines the two dependencies of nmea-parser-tests build completely fine and it's the:

g++ dataFiles.o nmea-parser.o -Wall -o 'nmea-parser-tests'

...that kicks out an error.

I understand it might be simply just a problem with how I have used the above G++ build command but I not really incredibly sure - any help would be greatly appreciated.

Note: I can't really give the entire source and header files but the nature of this work and the rights from the developer so if you think you might need any snippets of code, or the project hierarchy, or anything like that then feel free to ask it would just have to be on a per-request basis.

EDIT #1: I need to include a main() function yes although I am building a test program in use with BoostUTF that makes a main() itself. How can I incorporate this into the g++ command?

The BoostUTF-main.cpp:

#define BOOST_TEST_DYN_LINK
    #define BOOST_TEST_MODULE AllTests
    #include <boost/test/unit_test.hpp>

    /* This file generates the main() function for the Boost UTF test program.
     * The test suites themselves can be found in the other files in the 'tests/' directory.
     */
  • That can't be the actual makefile, the recipes need to be indented. – Barmar Feb 22 '22 at 22:53
  • Thanks for that. No, the formatting did not copy over well from VS Code and I fixed it hasty as the first line was only being included with the code block. – Benjamin Colligan Feb 22 '22 at 23:02
  • 2
    One of the files that you're linking needs to have a `main()` function. – Barmar Feb 22 '22 at 23:05
  • Fixed for your viewing pleasure. – Benjamin Colligan Feb 22 '22 at 23:05
  • Yup. C-family runtime startup calls the `main()` function. You haven't defined one. That's what `ld` is telling you: its runtime startup was left with an "undefined reference to `main`". You also have no `GPS::Position` constructor defined matching the calls it's also complaining about. – jthill Feb 22 '22 at 23:07
  • Right, got you, both of them have only a namespace within them. There is a BoostUTF-main.cpp file that is included in the /tests directory, this generates a main function for the test program, would I need to incorporate that? – Benjamin Colligan Feb 22 '22 at 23:08
  • Could I ask for my question to be reopened, this is not a problem of forgetting to include a main() function - I am using BoostUTF, I am asking how to take that into account when building. – Benjamin Colligan Feb 22 '22 at 23:25

0 Answers0