Hallo,
ik heb de volgende code en makefile. Het probleem is dat ik het niet geompileerd krijg wanneer ik in de main de static method van Test aanroep; Test::setInt(1); dus. Ik krijg dan steeds de volgende error:
g++ -c -g -Wall test.h main.cpp
g++ -g -o test test.o main.o
main.o(.text+0x12e): In function `main':
/home/joren/temp/main.cpp:10: undefined reference to `Test::setInt(int)'
collect2: ld returned 1 exit status
make: *** [test] Error 1
Het lijkt me aan de makefile te liggen, dus hopelijk kan hier iemand zeggen wat er ontbreekt of verkeerd staat in de makefile.
test.h
test.cpp
main.cpp
makefile
ik heb de volgende code en makefile. Het probleem is dat ik het niet geompileerd krijg wanneer ik in de main de static method van Test aanroep; Test::setInt(1); dus. Ik krijg dan steeds de volgende error:
g++ -c -g -Wall test.h main.cpp
g++ -g -o test test.o main.o
main.o(.text+0x12e): In function `main':
/home/joren/temp/main.cpp:10: undefined reference to `Test::setInt(int)'
collect2: ld returned 1 exit status
make: *** [test] Error 1
Het lijkt me aan de makefile te liggen, dus hopelijk kan hier iemand zeggen wat er ontbreekt of verkeerd staat in de makefile.
test.h
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| #ifndef MYTEST
#define MYTEST
#include <cstdio>
#include <iostream>
class Test
{
public:
Test(){}
~Test(){}
static void setInt(int i);
private:
static int m_int;
}; |
test.cpp
code:
1
| #include "test.h" |
main.cpp
code:
1
2
3
4
5
6
7
8
9
10
11
12
| #include <cstdio>
#include <iostream>
#include "test.h"
using namespace std;
int main(int argc, char *args[])
{
printf("blabla\n");
Test::setInt(1);
return(0);
} |
makefile
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| #Options for development
CC=g++
CFLAGS=-c -g -Wall
test: main.o test.o
$(CC) -g -o test test.o main.o
main.o: test.h main.cpp
$(CC) $(CFLAGS) test.h main.cpp
test.o: test.h test.cpp
$(CC) $(CFLAGS) test.cpp
clean:
rm -f *.o *.tab.c *.tab.h *.output *.yy.cpp *~ *.output y.tab.* parse |