simple makefile faults
Hello Ubuntu support,
I am testing the make function on Ubuntu Jammy:
-------------
PRETTY_NAME="Ubuntu 22.04.4 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.4 LTS (Jammy Jellyfish)"
VERSION_
ID=ubuntu
ID_LIKE=debian
HOME_URL="https:/
SUPPORT_URL="https:/
BUG_REPORT_URL="https:/
PRIVACY_
UBUNTU_
------------------
I have created 3 files in the same directory:
A) hello.cpp
#include "func.h"
int main() {
func(20);
func(100);
return 0;
}
B) func.cpp
#include "func.h"
void func(int i) {
std::cout << "You passed: " << i << std::endl;
}
C) func.h
#include<iostream>
void func(int i);
I have created a makefile called hello:
-----
all: hello.exe
hello.exe: hello.o func.o
@echo "Linking object files: hello.o and func.o"
g++ -o hello.exe hello.o func.o
@echo "Executable hello.exe has been created"
hello.o: hello.cpp func.h
@echo "compiling hello.cpp"
g++ -c hello.cpp
@echo "hello.o has been created"
func.o: func.cpp func.h
@echo "compiling func.cpp"
g++ -c func.cpp
@echo "func.o has been created"
-----
I use the makefile with 'make hello' I get this message
-----
g++ hello.cpp -o hello
/usr/bin/ld: /tmp/ccFKwfPP.o: in function `main':
hello.cpp:
/usr/bin/ld: hello.cpp:
collect2: error: ld returned 1 exit status
make: *** [<builtin>: hello] Error 1
-----
I have checked everything plus looked on the web for makefile tutorials. I can't understand why the makefile won't work.
Do you have any suggestions?
Best regards
Chris
Question information
- Language:
- English Edit question
- Status:
- Answered
- For:
- Ubuntu cpprest Edit question
- Assignee:
- No assignee Edit question
- Last query:
- Last reply:
Can you help with this problem?
Provide an answer of your own, or ask Chris for more information if necessary.