Linking problems - could namespace be the issue?

M

Martin Magnusson

I'm including a library in my program that I have wrapped in a
namespace, since it contains typdefes that clash with my own. Like
this:

namespace OPT{
#include "OPT/NLP.h"
#include "OPT/NLF.h"
}

When compiling, I get a number of undefined references to code in
OPT::, but I think I have included all libraries that I need.

Could the fact that I added a namespace be part of the problem?
 
C

chris

Martin said:
I'm including a library in my program that I have wrapped in a
namespace, since it contains typdefes that clash with my own. Like
this:

namespace OPT{
#include "OPT/NLP.h"
#include "OPT/NLF.h"
}

When compiling, I get a number of undefined references to code in
OPT::, but I think I have included all libraries that I need.

Could the fact that I added a namespace be part of the problem?

The short answer (which I'm sure you know) is yes.

The problem is probably that the functions which are refered to in these
two files have been not been compiled in the namespace. As you would
expect, if you put a function prototype into a namespace, then the
actual function itself must also be in the same namespace. Unless you
are willing edit this library, or the maintainers are willing to put the
functions into namespaces, then you might just have to put your own
typedefs into a namespace :)

Chris
 
J

Jonathan Mcdougall

I'm including a library in my program that I have wrapped in a
namespace, since it contains typdefes that clash with my own. Like
this:

namespace OPT{
#include "OPT/NLP.h"
#include "OPT/NLF.h"
}

If opt/nlp.cpp contains, for example,

void f()
{
}

and opt/nlp.h contains

void f();

then by including the file in a namespace, you get

namespace OPT
{
void f();
}

which is a different functions. Therefore, the one defined in nlp.cpp
is not the same, hence the undefined references.

If you don't have access to the source or if you can't modify it easily,
you would be better writing a wrapper for the library.


Jonathan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top