473,804 Members | 2,191 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 3369
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************* *********@hotma il.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
6761
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 options, but when i try to compile i get the errors listed below. Can anyone give me a suggestion on how to compile this program?
0
6144
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 file as folows. I need help to resolve them ASAP: cl /c /nologo /MDd /W3 /Od /GR /GM /Zi /GX /D "_DEBUG" /D " WIN32" /D "_W INDOWS" /D "_WINDLL" /D "_AFXDLL" /D "_MBCS" /D "_USRDLL" /
3
2003
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 1.1 (if so do I need Visual Studio 2003 - if I don't how do I tell it to re-compile with V 1.1 and not V 1.0).
3
4587
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 errors, any help would be 'greatly' appreciated! :) Thanks heaps! --------------------Configuration: CppRichTextItem - Win32 Debug-------------------- Compiling...
6
3324
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 with example
2
5748
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 in debug mode, the following errors happened: d:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xdebug(29): error C2365: 'new' : redefinition; previous definition was a 'member function' d:\Program Files\Microsoft Visual Studio...
6
2663
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 everytime I change a page on the production server I need to restart IIS to effect the change. If I don't restart IIS, it tries to recompile but gets and error ( 'cannot execute a program......vbc.exe......). Am I missing something which allows...
2
4146
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 message is: E:\software\development\boost_1_35_0\boost_1_35_0>bjam -- toolset=msvc-7.1 --variant=release --threading=multi --link=shared --
7
5776
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 compiled no problem. But I can't find the what the problem is with templates? Please help. The main is in test-linked-list.cpp. There are two template classes. One is List1, the other one is ListNode. The codes are below: // test-linked-list.cpp :...
0
10353
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10356
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10099
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9176
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7643
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6869
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4314
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 we have to send another system
2
3836
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.