Undefined reference to a function encode_character

Hi everyone,

Ok, so I wrote myself a makefile, which worked - I checked it with a simple cout << "Test\n" in the main itself. But now I have written a much more complicated function in another cpp file and when I make it, it keeps saying undefined reference to the function. I have included the header in main which is multitap.h, and ensured it is also included in multitap.cpp

Here is the makefile:

multitap: multitap.o main2.o
g++ -Wall -g -o multitap main2.cpp
main2.o: main2.cpp multitap.h
g++ -Wall -g -c main2.cpp
multitap.o: multitap.cpp multitap.h
g++ -Wall -g -c multitap.cpp
clean:
rm -f multitap.o main2.o multitap

Here is the top of main:
#include<iostream>
#include<fstream>

using namespace std;

#include"multitap.h"

int main(){
.................... <code>.......... return 0; }

Here is the top of multitap.cpp:

#include<iostream>
#include<cctype>
#include<cstring>
#include<fstream>

using namespace std;

#include "multitap.h"



The error that appears is:

make: *** [main.o] Error 1
make: Target `multitap' not remade because of errors.



Thanks for any help in advance!

- Ruby
Last edited on
looks like

multitap: multitap.o main2.o
g++ -Wall -g -o multitap main2.cpp

is wrong. You should link two object files not cpp file and unknown multitap file.
You should use somethink like

multitap: multitap.o main2.o
g++ multitap.o main2.o -o a.out
Last edited on
Hello,

that compiles, yes, but does not run in Linux when using ./multitap .
Also I added back the -Wall as this ensures warnings are given. What exactly does a.out do?

Thanks

Ruby
OOH I made it work - yay

multitap: multitap.o main.o
g++ -g -Wall -o multitap multitap.o main.o

main.o: main.cpp multitap.h
g++ -g -Wall -c main.cpp

multitap.o: multitap.cpp multitap.h
g++ -g -Wall -c multitap.cpp

clean:
rm -f multitap.o main.o multitap
Last edited on
Topic archived. No new replies allowed.