473,508 Members | 2,346 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Compile with different versions of Visual Studio

Hello,

Likely this has been asked before...

We have a library (in DLL form) that we distribute. The interface to the
library is all C, but within the library it uses C++ in many places.

Traditionally we've built our library with VC 6. We are considering moving
to VS .NET 2003 or VS 2005. However, we'd like to retain the ability to link
applications with the library when the application is still built with VC 6.

What issues are there with regard to linking in versions of the C runtime
library? E.g. Are the object files built with VC 6 going to try to link to
the VC 6 CRT, while the object files in the library built with VS 2003 or VS
2005 going to try to link with a different CRT?

Thanks.

Jun 26 '06 #1
4 3345
Hi cantatahost!
We have a library (in DLL form) that we distribute. The interface to the
library is all C, but within the library it uses C++ in many places.

Traditionally we've built our library with VC 6. We are considering moving
to VS .NET 2003 or VS 2005. However, we'd like to retain the ability to link
applications with the library when the application is still built with VC 6.

What issues are there with regard to linking in versions of the C runtime
library? E.g. Are the object files built with VC 6 going to try to link to
the VC 6 CRT, while the object files in the library built with VS 2003 or VS
2005 going to try to link with a different CRT?


1. You should link against the static version of the CRT (then you will
have no dependency to a special version of the CRT DLL)

2. You must have only C-Funktion interfaces! No dependecy to STL/MFC/ATL
in your Dll-interface!
Then it should be fine. You could also build the DLL with VC8 and link
it with VC6...

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Jun 26 '06 #2
>> We have a library (in DLL form) that we distribute. The interface to the
library is all C, but within the library it uses C++ in many places.


1. You should link against the static version of the CRT (then you will
have no dependency to a special version of the CRT DLL)

2. You must have only C-Funktion interfaces! No dependecy to STL/MFC/ATL
in your Dll-interface!

Then it should be fine. You could also build the DLL with VC8 and link
it with VC6...


Is it required to do both #1 and #2 in order for it to work? Or will either
#1 or #2 be fine?

For #2, is what I said above about how our library is written sufficient?

For the third paragraph, I don't understand whether you're saying this will
work only if I do #1 and/or #2, or if it will work all the time. Could you
please clarify?

Thanks.

Jun 26 '06 #3
>>> We have a library (in DLL form) that we distribute. The interface to the
library is all C, but within the library it uses C++ in many places.
1. You should link against the static version of the CRT (then you will
have no dependency to a special version of the CRT DLL)

2. You must have only C-Funktion interfaces! No dependecy to STL/MFC/ATL
in your Dll-interface!

Then it should be fine. You could also build the DLL with VC8 and link
it with VC6...


Is it required to do both #1 and #2 in order for it to work? Or will
either
#1 or #2 be fine?


1 is not a requirement, but you have to distribute the appropriate runtime
with your dll
if you don't link against the static runtime.
For #2, is what I said above about how our library is written sufficient?
at first glance it seems sufficient.
For the third paragraph, I don't understand whether you're saying this
will
work only if I do #1 and/or #2, or if it will work all the time. Could you
please clarify?


Jochen pointed out that you can indeed build your dll in VC8 and use it in
VC6.

one other thing that is also a definite requirement is that your dll has to
respect memory ownership.
see this article for more detailed explanation.
http://vcfaq.mvps.org/lang/9.htm

if your dll has only C style interfaces, and respects memory ownership,
you can build your dll in any VC version, and use it for building an
application in any VC version.

--

Kind regards,
Bruno van Dooren
br**********************@hotmail.com
Remove only "_nos_pam"
Jun 26 '06 #4
cantatahost wrote:
Is it required to do both #1 and #2 in order for it to work? Or will either
#1 or #2 be fine?


Both. #1 basically says that you can't mix runtime libraries. VC6 has a
different C runtime library (including memory manager) than VC8,
therefore you can't share the same RTL between the two modules. You have
to treat VC6 and VC8 as two completely incompatible environments, as if
they were developed by a different company.

It doesn't mean that you can't use dynamic RTL for your application, but
you can't share the same dynamic RTL between modules compiled with
different compilers. For example, if you use MFC from both the DLL and
the application, they were be completely independent copies of the MFC
library that have nothing to do with each other.

#2 states that only C-style interfaces are guaranteed to be
cross-compiler compatible. For example, you can always call a function
like this between independent modules:

int f(const char*);

However, a function like this is not compatible between VC6 and VC8:

int f(const std::string& s);
or
int f(const CString& s);

It doesn't mean you can't do object-oriented programming and share C++
classes between compilers, but you must fully understand what you're
doing if you choose to do so. I have a small article about this, which
is largely unfinished, but it contains a lot of information about
sharing classes between completely different compilers (even Borland and
Microsoft):

http://tweakbits.com/articles/dll/index.html

There's no easy way to tell what you can do, but one can certainly list
what you can't do in your cross-compiler DLL interfaces:

1. You can't use MFC (like CString), ATL, STL (std::vector, std::string)
in any of the functions that you plan to call between compiler
boundaries. VC6 and VC8 have completely independent implementation of
these libraries. Classes like CString, CWindow, std::string are not
byte-compatible between different versions of the compiler.

2. VC6 and 8 have totally different memory managers. Anything allocated
in a module must be deallocated in the same module. So if your DLL
allocates memory and returns pointer to it, you must not free that
pointer from you application. You DLL must also export a function that
frees the memory it allocated.

3. extern "C" __stdcall functions are the most portable, if they don't
have anything else but basic native C types in their signatures. Then
they can even be called from different languages, such as Pascal or
Fortran. __cdecl functions are also fine between C/C++ compilers.

4. You're not allowed to throw exceptions between compiler boundaries.
Your DLL must catch every exception and translate them into error codes.
Exception handling is implemented differently in VC6/8, so if your DLL
throws, you won't be able to catch it in your application.

5. I'm sure the list could go on. Anything that involves C++ features is
not guaranteed to work, unless it's implemented very carefully. If you
read my article, you'll learn how to use C++ classes between different
compilers using virtual functions to bind interface to implementation.
This (usually) works between different compiler vendors too. However,
you're still not allowed to use MFC and STL classes between the calls,
and you must still allocate and deallocate memory from the same module.

I've developed a safe string and vector class that you can use to pass
information between compiler boundaries. These classes are safe, because
they maintain an allocator in addition to the data, to ensure everything
is freed where it was allocated. If you link the exact same code to both
compilers, you should be able to use my classes across compilers, but I
provide my code without any warranty. If you don't understand what
you're doing, you can still very easily crash your program. Any data
shared between DLL modules assumes that you use the same data alignment,
otherwise binary compatibility can not be ensured.

Tom
Jun 26 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
6745
by: Brian | last post by:
Greetings: I am trying to compile the following code via command line. It compiles just fine in visual studio 2002 v7 so i took looked at the properties and i got the following command line...
0
6076
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug...
3
1979
by: Russell Gibson | last post by:
Hi I have created an ASP.Net web app using Visual Studio 2002 and .Net framework V 1.0. There is a bug fix I need in Framework V 1.1. Do I have to recompile my application with Framework V...
3
4563
by: Andrew Luke | last post by:
Hi all you C++ guru's! I'm 'very, very' new to C++ and I'm having a little trouble configuring my VS environment I think - when I try and compile some sample code I'm getting the following...
6
3283
by: Baskar RajaSekharan | last post by:
In C-sharp, I wnat to know whether the Component is compiled in Debug Mode or Run Mode through Code. How is it possible? Is there any way to Access the Config file and check? Please let me know...
2
5715
by: Qiao Yun | last post by:
I used vc++.net (visual studio .net ) to open a project which can work well in vc++6.0. I succeeded in compiling the project in vc++.net in release mode . But when I tried to compile the project...
6
2650
by: Tom | last post by:
I am developing my pages on my development machine and then copying to the production server. I am not pre-compiling, I am using the 'dynamic compile' feature. This is working fine except that...
2
4119
by: BruceWho | last post by:
I downloaded boost1.35.0 and built it with following command: bjam --toolset=msvc-7.1 --variant=release --threading=multi -- link=shared --with-system stage and it failed to compile, error...
7
5756
by: QiongZ | last post by:
Hi, I just recently started studying C++ and basically copied an example in the textbook into VS2008, but it doesn't compile. I tried to modify the code by eliminating all the templates then it...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7123
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
5627
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5052
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1556
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.