请问如何用wxWidgets库来写动态链接库? Topic is solved

这是wxWidgets论坛的中文版本。在这里,您可以用您的母语汉语讨论上面任一子论坛所涉及的所有关于wxWidgets的话题。欢迎大家参与到对有价值的帖子的中英互译工作中来!
Post Reply
freela
In need of some credit
In need of some credit
Posts: 7
Joined: Sun Dec 16, 2007 2:08 pm
Location: China

请问如何用wxWidgets库来写动态链接库?

Post by freela » Sun Mar 09, 2008 9:54 am

如题

wxWidgets有类支持动态链接库的开发吗?

我知道Code::Blocks的功能大多用动态链接库的形式来提供的,

那么它是如何实现的呢?(它的源代码可以在不同的平台生成具体的动态链接库.)

谢谢.

Utensil
Moderator
Moderator
Posts: 423
Joined: Sun Feb 03, 2008 11:38 am
Location: China

Post by Utensil » Sun Mar 09, 2008 2:57 pm

由于在各个平台写DLL的方式不一样,比如在Win下要有DLLMain,在Linux下则不用,仅仅取决于gcc的编译参数,再比如在Win下生成的是.dll,Linux下是.so,这里又涉及到Makefile的不同……

所以,wxWidgets没有办法去提供一个跨平台的类,也没有必要以类的形式来提供写跨平台的DLL的统一封装。(当然,wxWidgets提供了wxDynamicLibrary来进行跨平台的DLL的使用)

C::B的方式应该是在源文件中用了一些#ifdef对各个平台分别写startup和initialisation的代码。

可参见帖子http://forums.wxwidgets.org/viewtopic.p ... ssplatform

upCase在其中回答道:
Hi!
Using wxWidgets in shared objects requires you to follow some steps:
1. Write the platform specific startup and initialisation code.
2. Initialize the wxWidgets library yourself.
3. Encapsulate the parts of your code you want to have cross-platform.

A little bit more in detail:
1. On Windows this means that you'll have to create a DLL project and provide a proper DLLMain(), as well as properly defined exported symbols.
2. You'll have to use wxSetInstance() and wxEntryStart() (or simply wxInitialize() if you don't use GUI). You'll have to create a wxApp instance and, if you want to use the event system, start the main loop. IMPLEMENT_APP_NO_MAIN() will have to be used. Normaly wxWidgets does this itself when using IMPLEMENT_APP().
3. Encapsulate the major functionality in different sources and classes. Access them through the exported symbols in your DLL.
或者在论坛里搜索DLL cross-platform,也会有很多帖子讨论这个问题。

-Utensil
In fascination of creating worlds by words, and in pursuit of words behind the world.

On Github: http://utensil.github.com
Technical Blog in Chinese: http://utensil.iteye.com/

freela
In need of some credit
In need of some credit
Posts: 7
Joined: Sun Dec 16, 2007 2:08 pm
Location: China

Post by freela » Mon Mar 10, 2008 3:40 pm

谢谢您的帮助.

当我解决了这个问题的话,

我会用中文写个教程的.

Utensil
Moderator
Moderator
Posts: 423
Joined: Sun Feb 03, 2008 11:38 am
Location: China

Post by Utensil » Tue Mar 11, 2008 2:19 pm

freela wrote:当我解决了这个问题的话,

我会用中文写个教程的.
先替大家谢谢你了~ :)

-Utensil
In fascination of creating worlds by words, and in pursuit of words behind the world.

On Github: http://utensil.github.com
Technical Blog in Chinese: http://utensil.iteye.com/

soaringhawkzf
Knows some wx things
Knows some wx things
Posts: 35
Joined: Sun Nov 12, 2006 4:54 am

Post by soaringhawkzf » Tue Apr 15, 2008 1:45 am

Windows平台下DLL并不是一定需要DLLmain的
参考ACE的做法就行
注意文件名的处理,写一个跨平台的DLL封装库并不难

kevin_fly
Experienced Solver
Experienced Solver
Posts: 50
Joined: Tue Apr 15, 2008 12:55 am
Contact:

Post by kevin_fly » Tue Apr 15, 2008 2:10 am

网上这方面的资料太少了,好不容易找了个例子,还编译不过,有这方面编程经验的大虾,麻烦给大家共享一下你的经验,给个可以编译的sample,先谢啦

Post Reply