#Compiler error

28 messages · Page 1 of 1 (latest)

lusty plinth
#

Getting this error while using GNU Make, need help!
/usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/12.2.0/../../../../lib/Scrt1.o: in function `_start': /build/glibc/src/glibc/csu/../sysdeps/x86_64/start.S:103: undefined reference to `main' collect2: error: ld returned 1 exit status make: *** [Makefile:18: dboard.o] Error 1

Contents of Makefile:

# Include LSDTC++ for compatibility + less errors
CXX := /usr/bin/g++ -lstdc++
NAME := cheggers
LIBS := -lSDL2main -lSDL2 -lSDL2_image

debug: dmain.o dboard.o drenderw.o
    DEBUG := 1
    -echo -e '\033[1;33m>> Building debug version...\033[0m'
    -mkdir bin/debug
    $(CXX) src/main.o src/board.o src/render.o -o bin/debug/$(NAME) $(LIBS)

dmain.o: dboard.o drenderw.o
    -echo -e '\033[0;33m>> Compiling main source file..\033[0m'
    $(CXX) src/main.cpp -m64 -g -Wall -I include -I res

dboard.o:
    -echo -e '\033[0;33m>> Compiling board source files..\033[0m'
    $(CXX) src/b_egg.cpp src/b_board.cpp src/b_move.cpp -m64 -g -Wall -I include -I res

drenderw.o:
    -echo -e '\033[0;33m>> Compiling rendering source files..\033[0m'
    $(CXX) src/renderwindow.cpp -m64 -g -Wall -I include -I res```

Folder structure:
```.
├── bin/
├── hengine/
├── include/
│   ├── board.hpp
│   └── RenderWindow.hpp
├── LICENSE
├── Makefile
├── README.md
├── res/
│   ├── (irrelevant dir)
└── src/
    ├── b_board.cpp
    ├── b_egg.cpp
    ├── b_move.cpp
    ├── main.cpp
    └── renderwindow.cpp```
opaque yarrowBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.

river perch
#

undefined reference to 'main'

jolly lintel
#

well, means the linker can't find your main function 🤷‍♂️

lusty plinth
#

It all starts with dboard.o, should I change the order or something?

#

There is a main function in src/main.cpp

light plinth
#

Believe it or not, I have been developing software on Linux for 15 years and have never learned to write makefiles.
I have always worked with Qt/qmake (so do know .pro files) and in later years exclusively with CMake.

I would fully endorse CMake. It's a good skill to learn.
And with Ninja as the generator it's actually a killer combo.

(sidenote: I also use ccache to speed up compilation, but that's of little use to homework projects for anyone reading)

lusty plinth
#

oh aight
i was actually also thinking of using cmake, do you perhaps have any good tutorials for learning it?

light plinth
#

(laughs)
I must have used dozens, and I am struggling to think which ones.
I'll post them here as I remember them. Sorry.

One thing: Kitware's documentation is very good, but annoyingly it never actually gives examples on how to use the command.
You'll see it for yourself when you immerse yourself into CMake.

lusty plinth
#

Alright, no problem and thanks very much! I'll leave this thread open then

light plinth
#

Is yours a simple standalone project with no libraries, by any chance?
(looking at your folder structure).

If so, I could easily post a template project here.

You would still need to install CMake ofc.
I am sure there are plenty of people here willing to help get you off the ground.

lusty plinth
#

Yep, theres sdl2

#

And will use some networking library too

#

So not really standalone in that meaning

#

But a template project would still be appreciated

light plinth
#

So I wonder if SDL2 has a CMake config.
Looking...

#

https://www.youtube.com/watch?v=JXdqh0INIBI

This chap links directly with the libraries, rather than using CMake's find_package().
That would work, but I wouldn't rule out SDL2 having a proper CMake config.

Stuff for later.
For now, it would appear you have a good tutorial right there.

This tutorial assumes some basic understanding of C++ and Linux. The Visual Studio Code I'm using here has the most popular CMake and C++ Extensions installed, if you want to follow this along exactly, use the same. This will work with any editor and CMake in general. Please leave a comment if you have trouble. Thanks for coming to the channel t...

▶ Play video
lusty plinth
#

Thank you very much, kind stranger!! ❤️

light plinth
opaque yarrowBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.

lusty plinth
#

bump just in case i forget about this

opaque yarrowBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.

lusty plinth
#

æ

graceful bison
#

if you want to remember stuff just take notes

#

please don’t continuously bump your thread just to keep it open so you don’t forget this stuff

#

write it down on paper, use One Note or whatever, there are thousands of note taking apps

opaque yarrowBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.