Jump to content
  • Advertisement
Sign in to follow this  

Make-File Help

This topic is 4778 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay, I'm trying to figure out how to write a makefile. I first found a long and awful tutorial on how to write one from scratch... Then I got directed to simply make, automake, configure, autoconf. Then to somehow getting configure.ac files... I'm getting super lost, I am not getting anywhere on google. I even thought I found a way for Emacs to do it for me... Can anyone give me a good place to start? Tutorials? Advice? (Btw: I am using the make file with Intel's C++ Linux compiler, I am using Emacs to code in.)

Share this post

Link to post
Share on other sites
The manual for GNU make has a lot of explanation. It's not tutorial, but it does explain the concepts and has lots of examples. Here is a copy in HTML form: GNU Make

The core concept of make is pretty simple. A makefile consists of a list of rules which form a tree of files linked by dependencies. If any file in the tree is missing or is older than any of its children, a command is executed (which usually rebuilds the file from its children). The most important thing to understand is that make is not designed to execute a sequence of commands like a batch file. The commands that are executed and the order in which they are executed are completely determined by the dependency tree.

Share this post

Link to post
Share on other sites
Well I checked up on that, and I got somewhere.

I am trying to use a makeFile to compile the one line "Hello World" app.

This is my make file:
#(tabs before system commands, yes I know)
# lab1.make -- this is a comment line, ignored by make utility
all: Hello
lab1.out : Hello.o
icc -no-ipo -o lab1.out Hello.o
# above, we are saying lab1.out depends on main1.o, mylib.o and openfile.o
# and to create lab1.out we give the g++ command as shown on the next line

# which starts with a TAB although you cannot see that .
# note that the command : g++ -o lab1.out main1.o mylib.o openfile.o
# creates an executable file named lab1.out from the 3 object files respectively.
Hello.o: Hello.cpp
icc -c Hello.cpp
rm *.o
# above we are stating how to run the rule for clean, no dependencies,
# what we want is when we ask to do a "make -f lab1.make clean"
# that will not do anything except remove executable and object files
# so we can "clean out" our directory of unneeded large files.
# we only do a make clean when we want to clean up the files.


These are my errors:
make: *** No rule to make target `hello', needed by `all'. Stop.
halsafar@localhost:/share/Cpp/HelloWorld$ make -f MakeFile
icc -c Hello.cpp
cc Hello.o -o Hello
Hello.o(.text+0x19): In function `main':
Hello.cpp: undefined reference to `__intel_proc_init'
Hello.o(.text+0x1e):Hello.cpp: undefined reference to `std::cout'
Hello.o(.text+0x25):Hello.cpp: undefined reference to `std::cout'
Hello.o(.text+0x35):Hello.cpp: undefined reference to `std::cout'
Hello.o(.text+0x4c):Hello.cpp: undefined reference to `std::cout'
Hello.o(.text+0x58):Hello.cpp: undefined reference to `std::cout'
Hello.o(.text+0x61):Hello.cpp: more undefined references to `std::cout' follow
Hello.o(.text+0xe0): In function `main':
Hello.cpp: undefined reference to `std::ios_base::clear(std::_Iosb<int>::_Iostate, bool)'
Hello.o(.text+0xeb):Hello.cpp: undefined reference to `std::cout'
Hello.o(.text+0xf4):Hello.cpp: undefined reference to `std::cout'
Hello.o(.text+0x112):Hello.cpp: undefined reference to `std::cout'
Hello.o(.text+0x11b):Hello.cpp: undefined reference to `std::cout'
Hello.o(.text+0x135):Hello.cpp: undefined reference to `std::cout'
Hello.o(.text+0x13c):Hello.cpp: more undefined references to `std::cout' follow
Hello.o(.text+0x24f): In function `main':
Hello.cpp: undefined reference to `std::ios_base::clear(std::_Iosb<int>::_Iostate, bool)'
Hello.o(.text+0x25d):Hello.cpp: undefined reference to `std::uncaught_exception()'
Hello.o(.text+0x2b1):Hello.cpp: undefined reference to `std::ios_base::clear(std::_Iosb<int>::_Iostate, bool)'
Hello.o(.text+0x300):Hello.cpp: undefined reference to `__cxa_begin_catch'
Hello.o(.text+0x321):Hello.cpp: undefined reference to `std::ios_base::clear(std::_Iosb<int>::_Iostate, bool)'
Hello.o(.text+0x329):Hello.cpp: undefined reference to `__cxa_end_catch'
Hello.o(.text+0x333):Hello.cpp: undefined reference to `__cxa_end_catch'
Hello.o(.text+0x395):Hello.cpp: undefined reference to `std::cout'
Hello.o(.text+0x3ae):Hello.cpp: undefined reference to `std::cout'
Hello.o(.text+0x3d2):Hello.cpp: undefined reference to `std::cout'
Hello.o(.text+0x3e3):Hello.cpp: undefined reference to `std::cout'
Hello.o(.text+0x3fa):Hello.cpp: undefined reference to `std::cout'
Hello.o(.text+0x4b6): In function `__sti__$E':
Hello.cpp: undefined reference to `std::ios_base::Init::Init()'
Hello.o(.text+0x4c5):Hello.cpp: undefined reference to `std::ios_base::Init::~Init()'
Hello.o(.text+0x4d4):Hello.cpp: undefined reference to `std::_Winit::_Winit()'
Hello.o(.text+0x4e3):Hello.cpp: undefined reference to `std::_Winit::~_Winit()'
Hello.o(.gnu.linkonce.t._ZNSo6sentryD1Ev[.gnu.linkonce.t._ZNSo6sentryD1Ev]+0x1a): In function `std::basic_ostream<char, std::char_traits<char> >::sentry::~sentry()':
Hello.cpp: undefined reference to `std::uncaught_exception()'
Hello.o(.gnu.linkonce.t._ZNSo6sentryD1Ev[.gnu.linkonce.t._ZNSo6sentryD1Ev]+0x72):Hello.cpp: undefined reference to `std::ios_base::clear(std::_Iosb<int>::_Iostate, bool)'
Hello.o(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
make: *** [Hello] Error 1

Hello.cpp compiles fine if I:
icc Hello.cpp

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
Try replacing lab1.out with hello.

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
SHELL = /bin/sh
CC = g++
OBJECTS = hello.o

all : hello

hello : $(OBJECTS)
$(CC) $(OBJECTS) -o $@

hello.o :
$(CC) -c hello.cpp

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
Here is a pretty good tutorial on writing makefiles.


Share this post

Link to post
Share on other sites
Most of your errors don't seem to be to do with your makefile as such, rather due to not passing in the correct libraries to gcc. I.e., if you use the same commands to compile and link manually, the errors will probably still appear.

Share this post

Link to post
Share on other sites
In a lot of cases, it is easy to go too far with a Makefile.

If I had a file called bingo.cpp, I could just type:

make bingo

and it would compile fine, even without a Makefile present. If it depended on routines in bingonumber.cpp, I would design a Makefile like this:

bingo: bingonumber.o

Now I can type "make bingo" and it will automatically compile bingonumber.o first, and then link it into bingo.

Here's an example of the Makefile I use in my examples directory:

CPPFLAGS += -Wno-deprecated-declarations
BINS = openal openil function_pointer inheritance_test precision
OPENAL = -lopenal -lalut
OPENGL = -lGL -lGLU -lglut
LIBXML = -I/usr/local/include/libxml2 -L/usr/local/lib -lxml2 -lz

all: ${BINS}
openal: LDFLAGS += ${OPENAL}
openil: LDFLAGS += ${OPENGL} ${OPENIL}

rm ${BINS}

Note that if I just type "make", it will make everything, because "all" is the first entry. I can still, however just type "make xml2" and it will make only that. This doesn't show a good example of dependencies, however.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!