On Mon, Jan 30, 2012 at 10:52 AM, John Peterson <jwpeter...@gmail.com> wrote:
>
> Anyway, I think we've at least tracked the issue down to the macro
>
> FUNCTIONPARSER_INSTANTIATE_TYPES
>
> which appears in both fparser.cc and fpoptimizer/optimize_main.cc.  If
> I comment out the macro from one of those files, fparser seems to link
> fine (no duplicate symbols).
>
> However I don't know what effect this will have on executables,
> testing that now...

Commenting out the macro causes undefined symbols in the executables,
so the fix isn't going to be that easy.

I can recreate the problem on the Mac fairly simply, and it kind of
baffles me... seems like it might be a bug in apple's compilers?

Basically all you have to do is create two .C files which both try to
do explicit template instantiation and the linker gets confused:


// ============================== foo.h
#include <iostream>

// Declaration of templated class.  Will be instantiated in both
// foo1.C and foo2.C to test whether this leads to linking errors.
template <class T>
class Foo
{
public:
  T t;
  void print() { std::cout << "t=" << t << std::endl; }
};



// ============================== foo1.C
#include "foo.h"

// Explicit instantiation for int
template class Foo<int>;




// ============================== foo2.C
#include "foo.h"

// Explicit instantiation for int
template class Foo<int>;




g++ -c foo1.C -o foo1.o
g++ -c foo2.C -o foo2.o
g++ -dynamiclib  -o foo.dylib foo1.o foo2.o
ld: duplicate symbol Foo<int>::print()   in foo2.o and foo1.o
collect2: ld returned 1 exit status
make: *** [foo.dylib] Error 1



I'm pretty sure multiple instantiations in different translation units
are allowed by the standard... the linker should be able to sort them
out.

Is that not the case?

The same code compiles just fine on linux.

And yes, I've also tried linking on the Mac with all the various
options like libmesh uses (-flat_namespace, etc.) and it doesn't seem
to make any difference.

-- 
John

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Libmesh-devel mailing list
Libmesh-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libmesh-devel

Reply via email to