[mingw - C/C++] Cannot export symbols

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[mingw - C/C++] Cannot export symbols

ernesto bascon
Hi everybody:


I am writing this very small test class using mingw:


#ifdef DLL
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT __declspec(dllimport)
#endif


#include <stdio.h>


class DLLEXPORT MyTestClass
{
        public:
                MyTestClass()           { }
                ~MyTestClass()          { }
                int GetSuccessor(int a)    { return a + 1; }
                int GetPredecessor(int a)  { return a - 1; }



};



As you can see, I want to export that class into a DLL.
So, I do:

g++ -shared -o test.dll test.cpp -Wl,-output-def=test.def -DDLL


and my DLL is an empty DLL with no exported symbols!!! (and the .def
file has length 0).


Am I doing something wrong? I am creating a C++ library, and I want to
export only classes into my DLL.


Thanks in advance


Ernesto





-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|

Re: [mingw - C/C++] Cannot export symbols

Danny Smith
From: "ernesto bascón pantoja"

> Hi everybody:
>
>
> I am writing this very small test class using mingw:
>
>
> #ifdef DLL
> #define DLLEXPORT __declspec(dllexport)
> #else
> #define DLLEXPORT __declspec(dllimport)
> #endif
>
>
> #include <stdio.h>
>
>
> class DLLEXPORT MyTestClass
> {
>         public:
>                 MyTestClass()           { }
>                 ~MyTestClass()          { }
>                 int GetSuccessor(int a)    { return a + 1; }
>                 int GetPredecessor(int a)  { return a - 1; }
>
>
>
> };
>
>
>
> As you can see, I want to export that class into a DLL.
> So, I do:
>
> g++ -shared -o test.dll test.cpp -Wl,-output-def=test.def -DDLL
>
>
> and my DLL is an empty DLL with no exported symbols!!! (and the .def
> file has length 0).
>


The functions are all inline.  Either move the definitions out of the class
definition or add -fkeep-inline-functions to command line.

Danny

>
> Am I doing something wrong? I am creating a C++ library, and I want to
> export only classes into my DLL.
>
>
> Thanks in advance
>
>
> Ernesto
>
>
>
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
> from IBM. Find simple to follow Roadmaps, straightforward articles,
> informative Webcasts and more! Get everything you need to get up to
> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
> _______________________________________________
> MinGW-users mailing list
> [hidden email]
>
> You may change your MinGW Account Options or unsubscribe at:
> https://lists.sourceforge.net/lists/listinfo/mingw-users




-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. <a href="http://ads.osdn.com/?ad_idt77&alloc_id492&op=click">http://ads.osdn.com/?ad_idt77&alloc_id492&op=click
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|

Re: [mingw - C/C++] Cannot export symbols

ernesto bascon
Yeap, you are right!

Thanks a lot, Danny! :)


ernesto





-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|

Re: [mingw - C/C++] Cannot export symbols

ernesto bascon
In reply to this post by Danny Smith
It's me again:

I created this very small program:

main.h
------
#ifdef DLL
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT __declspec(dllimport)
#endif

class DLLEXPORT A
{
 public:
  A();
  virtual ~A();

  virtual const char* GetMessage();
};

class DLLEXPORT B : public A
{
 public:
  B();
  virtual ~B();

  virtual const char* GetMessage();
};


main.cpp
----------
#include <stdio.h>

#include "main.h"

A::A()
{
 printf("A constructor\n");
}

A::~A()
{
 printf("A destructor\n");
}

const char* A::GetMessage()
{
 return "Hello A world";
}

B::B()
{
 printf("B constructor\n");
}

B::~B()
{
 printf("B destructor\n");
}

const char* B::GetMessage()
{
 return "B sides are better";
}

I compiled it using:

g++ -c main.cpp -DDLL
ar -r main.a main.o
g++ -shared -o main.dll main.a -Wl,-output-def,main.def

and it does not export any symbols, but doing a:

g++ -shared -o main.dll main.o -Wl,-output-def,main.def

publishes everything perfectly.

Any ideas?


ernesto





-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users