Mixing compilers mingw and Open Watcom?

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

Mixing compilers mingw and Open Watcom?

lollisoft
Hi,

my code is C++ code and I do use DLL's. I start using the main DLL  
(lbHook.dll) to be ported
to mingw. Then I'll start over with the real work of code that Open  
Watcom couldn't compile yet,
thus I'll use mingw for it.

lbHook.dll is the central DLL and the only DLL I link to other DLL's  
and executables. Other DLL's
are loaded at runtime and classes are instantiated via functors.

My current trial to use extern "C" for the function bool isVerbose()  
produces the following
when I create a list of exported functions from the DLL:

__imp_isVerbose

But the Open Watcom compiler expects

__imp__isVerbose

I have not yet tried classes that are also exported in that said module.

What options do I have to solve this?

Thanks

Lothar

-- | Rapid Prototyping | XSLT Codegeneration | http://www.lollisoft.de
Lothar Behrens
Heinrich-Scheufelen-Platz 2
73252 Lenningen










------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
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: Mixing compilers mingw and Open Watcom?

Earnie Boyd
Lothar Behrens wrote:
> Hi,
>
> my code is C++ code and I do use DLL's. I start using the main DLL
> (lbHook.dll) to be ported
> to mingw. Then I'll start over with the real work of code that Open
> Watcom couldn't compile yet,
> thus I'll use mingw for it.
>    

Why not just use MinGW for all of it?  
http://www.mingw.org/wiki/MixingCompilers

> lbHook.dll is the central DLL and the only DLL I link to other DLL's
> and executables. Other DLL's
> are loaded at runtime and classes are instantiated via functors.
>
> My current trial to use extern "C" for the function bool isVerbose()
> produces the following
> when I create a list of exported functions from the DLL:
>
> __imp_isVerbose
>
> But the Open Watcom compiler expects
>
> __imp__isVerbose
>    

Perhaps a manually created alias in the library definition file that you
would use with Watcom's linker to create a library file.  Don't know if
it would work, just guessing about how it could be done.

Earnie

------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
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: Mixing compilers mingw and Open Watcom?

lollisoft

Am 20.03.2010 um 16:03 schrieb Earnie:

> Lothar Behrens wrote:
>> Hi,
>>
>> my code is C++ code and I do use DLL's. I start using the main DLL
>> (lbHook.dll) to be ported
>> to mingw. Then I'll start over with the real work of code that Open
>> Watcom couldn't compile yet,
>> thus I'll use mingw for it.
>>
>
> Why not just use MinGW for all of it?
> http://www.mingw.org/wiki/MixingCompilers

I have a very modular software with only one main DLL for all other  
stuff. This makes it easier to use mixed compilers.
My goal is to avoid porting of all my code to a new compiler.

In a long term I may switch to MinGW completely.

>
>> lbHook.dll is the central DLL and the only DLL I link to other DLL's
>> and executables. Other DLL's
>> are loaded at runtime and classes are instantiated via functors.
>>
>> My current trial to use extern "C" for the function bool isVerbose()
>> produces the following
>> when I create a list of exported functions from the DLL:
>>
>> __imp_isVerbose
>>
>> But the Open Watcom compiler expects
>>
>> __imp__isVerbose
>>
>
> Perhaps a manually created alias in the library definition file that  
> you
> would use with Watcom's linker to create a library file.  Don't know  
> if
> it would work, just guessing about how it could be done.
>

I do define two versions of my exported functions.

Header

#ifdef __WATCOMC__
extern "C" void DLLEXPORT API test(char* text);
#endif
#ifdef __MINGW32__
extern "C" void DLLEXPORT API _test(char* text);
#endif

MinGW DLL

extern "C" void DLLEXPORT API _test(char* text) {
         test_impl(text);
}

Currently I do not plan to link MinGW DLL's against other MinGW DLL's  
that will use test. Thus I do not need to implement a watcom wrapper :-)

My tests work, but I struggle with a case when using classes from the  
DLL (pure abstract classes works) with a protected destructor:

Header:

class ITest {
protected:
        ITest() {}
public:
         virtual bool API getbool() = 0;
         virtual void API test(char* text, char* p2) = 0;
         virtual void API release() = 0;
};

DLL code:

class Test : public ITest {
public:
         Test();
         virtual ~Test();

         bool API getbool();
         void API test(char* text, char* p2);

         virtual void API release();
};

Test::Test() {
         printf("Instance of Test created.\n");
}

Test::~Test() {
         printf("Instance of Test deleted.\n");
}

bool API Test::getbool() {

}

void API Test::test(char* text, char* p2) {
         test_impl(text);
         test_impl(p2);
}

void API Test::release() {
         printf("Test::release() called.\n");
         delete this;
}

void test_impl(char* text) {
     printf("Hello from test DLL. Text is '%s'.\n", text);
}

extern "C" void DLLEXPORT API _test(char* text) {
         test_impl(text);
}

extern "C" bool DLLEXPORT API _getbool() {
     return true;
}

extern "C" DLLEXPORT ITest* API _gettest() {
     return new Test();
}

Executable:

int main() {
     test("From text.exe");
     ITest* t = gettest();

     t->test("From object out of test.exe", "p2");

     if (getbool()) printf("Have true.\n");

     t->release();

     return 0;
}

Output with protected destructor:

Hello from test DLL. Text is 'From text.exe'.
Instance of Test created.
Have true.
Hello from test DLL. Text is 'From object out of test.exe'.
Hello from test DLL. Text is 'p2'.

Output without protected destructor:

Hello from test DLL. Text is 'From text.exe'.
Instance of Test created.
Hello from test DLL. Text is 'From object out of test.exe'.
Hello from test DLL. Text is 'p2'.
Have true.
Test::release() called.
Instance of Test deleted.

Look at the order of the printf lines. Do you have any explanations  
why this happens?

Disabling the delete operator this way I may ensure my objects to be  
deleted inside of the DLL, but in that sample it will not work.

Thanks

Lothar

> Earnie
>
> ------------------------------------------------------------------------------
> Download Intel® Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> MinGW-users mailing list
> [hidden email]
>
> This list observes the Etiquette found at
> http://www.mingw.org/Mailing_Lists.
> We ask that you be polite and do the same.  Disregard for the list  
> etiquette may cause your account to be moderated.
>
> _______________________________________________
> You may change your MinGW Account Options or unsubscribe at:
> https://lists.sourceforge.net/lists/listinfo/mingw-users
>

-- | Rapid Prototyping | XSLT Codegeneration | http://www.lollisoft.de
Lothar Behrens
Heinrich-Scheufelen-Platz 2
73252 Lenningen










------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
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: Mixing compilers mingw and Open Watcom?

lollisoft
I got the remaining problem of not really deleting my object done.

It seems that mingw and open watcom have a different handling of  
vtable entries. When I move the virtual destructor
at the end of the class declaration, open watcom can correctly delete  
my object.

class ITest {
public:
         virtual void API release() = 0;

         virtual bool API getbool() = 0;
         virtual void API test(char* text, char* p2) = 0;

protected:
         virtual ~ITest() = 0;
};

With doing the destructor private the programmer could not delete the  
object outside of the DLL - except with the release() function.
And that way open watcom linker doesn't complain about missing  
destructor as it will complain about it's usage at compile time.

The release function if similar to COM's release and in my real code I  
implement reference counting. The virtual destructor is implemented in  
the DLL.

I think this scheme will help mixing compilers and also enables  
classes to be used across compilers plus avoiding misusing the delete  
operator.

Lothar

-- | Rapid Prototyping | XSLT Codegeneration | http://www.lollisoft.de
Lothar Behrens
Heinrich-Scheufelen-Platz 2
73252 Lenningen










------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

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