1

Hey StackOverflow community I have a question that I can't seem to solve for the life of me.

I have a C++ application, main.cpp, that calls another class, MainMenu.cpp, that has a header file associated with it. In MainMenu.cpp we call an external library to use for various purposes, however when using my Makefile this is my output:

/usr/bin/ld: MainMenu.cpp:(.text+0x1b04): undefined reference to libarary::method()'

This is my Makefile (Sorry if it is a bit disorganized):

all: main.o MainMenu.o
    g++ ./CompiledSources/main.o ./CompiledSources/MainMenu.o -o \
    ./OutputCompiledSource/main \
    -lsfml-graphics -lsfml-window -lsfml-system -lsfml-network -lsfml-audio
    ./OutputCompiledSource/./main
MainMenu.o:
    g++ -c -Wall ./GameWindow/MainMenu.cpp -o ./CompiledSources/MainMenu.o
main.o:
    g++ -c -Wall main.cpp -o ./CompiledSources/main.o

And here is my file structure:

project
│   main.cpp    
└───GameWindow
│   │   MainMenu.cpp
│   │   MainMenu.h   
└───TimeStep
    │   Library.hpp // This includes all the header files below  and what I "include" in MainMenu.cpp
    └───LibaryFiles
        │   File1.hpp
        │   File1.cpp
        │   ...

I have tried the -L option in the Makefile but cant seem to get the right combination for it to work, so any help would be appreciated!

I can also provide additional info if needed!

(edit): When I think about it, it is less of a library linking issue and more of a class linking issue in general, sorry if that added necessary confusion so I changed the title of the post.

Nick Anson
  • 11
  • 3

0 Answers0