|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Greetings,
I am trying to create a class library/dll with C++ and I am running into a lot of trouble. I know that this is a C++ forum and not one specific to windows or VS 2005 but I'm hoping someone call me. I would like to create a class library so that I can put classes that I reuse a lot into their own modules. I played around with it for awhile and had no luck. It was really easy to do in C# but C++ does not seem to be so easy. I saw a lot of websites referencing exporting and importing symbols but they all seem to relate to functions. How do you decorate the class so that you can export the whole class and create an instance of it in the calling program. Thanks. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On 2007-10-15 22:06, djbaker@gmail.com wrote:
> Greetings, > I am trying to create a class library/dll with C++ and I am running > into a lot of trouble. I know that this is a C++ forum and not one > specific to windows or VS 2005 but I'm hoping someone call me. > > I would like to create a class library so that I can put classes that > I reuse a lot into their own modules. I played around with it for > awhile and had no luck. It was really easy to do in C# but C++ does > not seem to be so easy. > > I saw a lot of websites referencing exporting and importing symbols > but they all seem to relate to functions. How do you decorate the > class so that you can export the whole class and create an instance of > it in the calling program. You are right about this not being a C++ question, so for future questions regarding DLLs please use a more appropriate group (I think a win32 programming group would be the right choice). Here is a tutorial to get you started: http://www.codeproject.com/dll/RegDLL.asp -- Erik Wikström |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
=?UTF-8?B?RXJpayBXaWtzdHLDtm0=?= <Erik-wikstrom@telia.com> wrote in
news:imQQi.11431$ZA.7495@newsb.telia.net: > You are right about this not being a C++ question, so for future > questions regarding DLLs please use a more appropriate group (I think a > win32 programming group would be the right choice). Here is a tutorial > to get you started: http://www.codeproject.com/dll/RegDLL.asp I think ghetto-izing shared library implementation should be discouraged. Instead, consider ways to design sharable libraries that can be used on many platforms (not just Win32). For example, is there any standardization effort in creating syntactic linkage hints such as this kind of import/export decorator? For example, right now I'm working on a proprietary closed-source library that's initially implemented as a Win32 DLL but I'd like to design it so that it can be easily rebuilt on Linux, Solaris, Mac, etc. What's the best way to structure one's code to accomplish that? My approach has been to create an auxiliary header (<MyLibrary/_internal.h> ) that gets included in each public header and defines linkage macros that get used for each class and function that needs this. I put my headers in project/include/MyLibrary, and library clients add project/include to their -I option. This allows me to use simple names for headers and keeps them in a separate #include namespace. (Perhaps project/include/Vendor/Library) would be preferable, if a vendor produces several libraries.) My biggest hassle so far in portable shared libraries is the use of STL objects (particularly containers) in public classes. The MS compiler will whine that those classes need DLL linkage. Is gcc under Linux subject to the same problem? How can I design the classes so that I don't face this? |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On 2007-10-15 23:59, Kenneth Porter wrote:
> =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?= <Erik-wikstrom@telia.com> wrote in > news:imQQi.11431$ZA.7495@newsb.telia.net: > >> You are right about this not being a C++ question, so for future >> questions regarding DLLs please use a more appropriate group (I think a >> win32 programming group would be the right choice). Here is a tutorial >> to get you started: http://www.codeproject.com/dll/RegDLL.asp > > I think ghetto-izing shared library implementation should be discouraged. > Instead, consider ways to design sharable libraries that can be used on > many platforms (not just Win32). For example, is there any standardization > effort in creating syntactic linkage hints such as this kind of > import/export decorator? There is very little in the way of standardising shared libraries. The latest effort I can find on standard committee's site (N2407) is little more than a description of the problem, an investigation of how it is done on Windows and Linux and a suggestion of how to specify what should be exported or not. This late in the process I would not expect it to be included in the next version of the standard. > My biggest hassle so far in portable shared libraries is the use of STL > objects (particularly containers) in public classes. The MS compiler will > whine that those classes need DLL linkage. Is gcc under Linux subject to > the same problem? How can I design the classes so that I don't face this? I *think* that by default everything is exported on Linux, while you have to explicitly export it on Windows. -- Erik Wikström |
|
![]() |
| Outils de la discussion | |
|
|