Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED] Makefile undefined references  (Read 1432 times)

0 Members and 1 Guest are viewing this topic.

sfmlearner

  • Newbie
  • *
  • Posts: 9
    • View Profile
[SOLVED] Makefile undefined references
« on: May 23, 2022, 05:34:28 pm »
Hi, I saw that there already are Makefile threads, but I couldn't find the solution after hours of trying.

This is my project structure:

sorting-visualizer/
├─ lib/
│  ├─ SFML-2.5.1/
│  │  ├─ include/
│  │  ├─ lib/
├─ src/
│  ├─ [cpp and h fiiles...]
├─ Makefile

Im trying to build the project using Makefile, here is the output when I try to run make: https://pastebin.com/xa2QgC3E

And here is my Makefile:

# SFML
SFML_DIR=./lib/SFML-2.5.1

SFML_LIBS=-lsfml-graphics -lsfml-window -lsfml-system

# Steps
steps: compile clean

# Compile source files
main.o: ./src/main.cpp
        g++ -c ./src/main.cpp -I$(SFML_DIR)/include

Sortable.o: ./src/Sortable.cpp
        g++ -c ./src/Sortable.cpp -I$(SFML_DIR)/include

SortAlgorithms.o: ./src/SortAlgorithms.cpp
        g++ -c ./src/SortAlgorithms.cpp -I$(SFML_DIR)/include

SortController.o: ./src/SortController.cpp
        g++ -c ./src/SortController.cpp -I$(SFML_DIR)/include

Utils.o: ./src/Utils.cpp
        g++ -c ./src/Utils.cpp -I$(SFML_DIR)/include

# Compile binary
compile: main.o Sortable.o SortAlgorithms.o SortController.o Utils.o
        g++ *.o -o sorting-visualizer -L$(SFML_DIR)/lib $(LIBS)

        @echo
        @echo Done! Run ./sorting-visualizer to open

# Clean object files after building
clean:
        @rm *.o
 

Im using Arch Linux, should I use CMake instead? It would be great if the project could be built easily for Windows and macOS too, that's why I'm including the libraries instead of using the package manager.

Thanks!
« Last Edit: May 23, 2022, 06:46:24 pm by sfmlearner »

sfmlearner

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Makefile undefined references
« Reply #1 on: May 23, 2022, 05:52:04 pm »
I decided to use CMake instead, using CMake will be easier to port the project to other platforms

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Makefile undefined references
« Reply #2 on: May 23, 2022, 06:39:01 pm »
Yeah, I highly recommend CMake as it's much more flexible, especially when it comes to cross-platform and cross-compiler support.

Here's a template that might help you get things started: https://github.com/eXpl0it3r/cmake-sfml-project
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

sfmlearner

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Makefile undefined references
« Reply #3 on: May 23, 2022, 06:45:56 pm »
Thanks! I ended up using CMake and was so much easier  :) , here is the CMakeLists.txt that I made, if someone is having the same issue:

cmake_minimum_required(VERSION 3.22)
project(sorting-visualizer)

set(SFML_DIR "lib/SFML-2.5.1/lib/cmake/SFML")


find_package(SFML COMPONENTS graphics window REQUIRED)

add_executable(sorting-visualizer src/main.cpp src/Sortable.cpp src/SortAlgorithms.cpp src/SortController.cpp src/Utils.cpp)

target_link_libraries(sorting-visualizer sfml-graphics sfml-window)
 

 

anything