c++ - Linker can't find function definition in a namespace -


i /tmp/ccnl7yz1.o: in function 'main': main.cpp:(.text+0x70): undefined reference 'dng::gendungeon()' main.cpp:(.text+0xf0): undefined reference 'dng::clrdungeon(char**)' collect2: error: ld returned 1 exit status error when i'm trying compile program. worked great before added namespace functions. i'm compiling this: g++ -std=c++11 main.cpp dungeon.cpp

dungeon.h

namespace dng {     char** gendungeon();     void clrdungeon(char**);      class dungeon {     //methods , 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(){} -> */ 

main.cpp

#include "dungeon.h"  int main ()  {     //stuff     auto dungeon = dng::gendungeon();     //stuff     dng::clrdungeon(dungeon);     return 0; } 

i tried make .o files myself g++ -std=c++11 -c main.cpp g++ -std=c++11 -c dungeon.cpp , link them, got same error. can problem?

enclose function definitions in namespace dng declared.

#include "dungeon.h"  namespace dng { char** gendungeon()  {     //stuff } void clrdungeon(char** dungeon)  {     //another stuff } //... } 

or use qualified names.

include "dungeon.h"  using namespace dng;  //...  char** dng::gendungeon()  {     //stuff } void dng::clrdungeon(char** dungeon)  {     //another stuff } 

otherwise, functions defined in global namespace, , result, declared 4 functions: 2 in namespace dng , 2 in global namespace.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -