I get this /tmp/ccnL7Yz1.o: In function 'main':
main.cpp:(.text+0x70): undefined reference to 'dng::genDungeon()'
main.cpp:(.text+0xf0): undefined reference to 'dng::clrDungeon(char**)'
collect2: error: ld returned 1 exit status
error when I'm trying to compile my program. It worked great before I added namespace functions. I'm compiling it like this: g++ -std=c++11 main.cpp Dungeon.cpp
Dungeon.h
namespace dng {
char** genDungeon();
void clrDungeon(char**);
class Dungeon {
//Methods and variables
}
}
Dungeon.cpp
#include "Dungeon.h"
using namespace dng;
char** genDungeon()
{
//Stuff
}
void clrDungeon(char** dungeon)
{
//Another Stuff
}
/*Implementation of class methods
void Dungeon::genStart(){} -> like this */
main.cpp
#include "Dungeon.h"
int main ()
{
//Stuff
auto dungeon = dng::genDungeon();
//Stuff
dng::clrDungeon(dungeon);
return 0;
}
I also tried to make .o
files by myself g++ -std=c++11 -c main.cpp
g++ -std=c++11 -c Dungeon.cpp
and then link them, but got the same error. What can be the problem?
using namespace
. – Backer