VS2005 Project migration to eclipse CDT

Source: Internet
Author: User

The original project was created under VS2005, migrated to eclipse CDT 3.3.2 + MINGGW, and added makefile files.

The original VS2005 project sample, realized the class SampleClass encapsulation, generated Sample.dll file. Project source files include StdAfx.h, Stdafx.cpp, Targetver.h, Dllmain.cpp, Sample.def, Sample.h, Sample.cpp, SampleClass.h, SampleClass.cpp. where stdafx.h, Stdafx.cpp, Targetver.h used to build precompiled header file sampleclass.pch and precompiled type file Stdafx.obj;dllmain.cpp, Sample.def to load DLL entry function files and module definition files; SampleClass.h, SampleClass.cpp declares and defines class SampleClass; Sample.h, Sample.cpp defines the export function of the DLL application.


First create the project sample under Eclipse, and then use the Import function to import the *.h, *.cpp, *.def, *.txt files of the original project into the sample project VS2005. Refer to IBM Developworks, "Migrating visual Studio C and C + + projects to Eclipse CDT" (http://www.ibm.com/developerworks/cn/opensource/ os-ecl-vscdt/). It is also important to note that the link article uses the IDE as VC6 to export and modify makefile, and VS2005 already does not provide the export Makefile file feature.

Next, you write the makefile file (you need to add the g++ command yourself because the DLL calls the compilation problem). The implementation of the multi-file (Sample.cpp and SampleClass.cpp) compiled links, the solution has two: one is in the Sample.cpp include "SampleClass.cpp", as a file compiled The second is to add the g++ parameter in makefile to compile two CPP files separately, then link to the DLL. The second method is used in this article.

The g++ parameters used are described below (Note that the TAB key is not a space before g++):

The-shared parameter is used to create a shared library, which is a DLL in Windows. One should note that "-O Sample.dll sample.o sampleclass.o" in two. o files must be included, otherwise error undefined reference to ' Sampleclass::checklicense (char const*) ' etc;
-WL,--Out-implib This parameter is mainly generated. A this file;-wl waits for the next message to be connected,--out-implib is used by the connector LD to create the import library needed to connect the DLL;
-dfilterplugin_exports to set the macro filterplugin_exports. The Filterplugin_exports macro will be set manually at compile time, when the macro Filterplugin_api is set to __declspec (dllexport). This will enable GCC to compile this DLL. When a DLL is called from an executable, the Filterplugin_exports macro is not set and the FILTERPLUGIN_API macro is set to __declspec (dllimport), which causes the function to be visible within the invocation scope. __declspec (dllexport) and __declspec (dllimport) are macros used to create DLLs.

If you need to create an EXE executable, you need to add
SAMPLE.EXE:SAMPLE.O Sample.dll
g++-o Sample.exe sample.o-l./-lmessage
Where-l Specifies the connection library path,-lmessage (or-l message) specifies the DLL's import library.
See the minimalist GNU for Windows a sample DLL (Http://www.mingw.org/MinGWiki/index.php/sample%20DLL) for specific information. PHPSESSID=ABCE11154A632520EB), as well as the GNU make manual.

-----------------

The makefile file is as follows:

Cxxflags =-o2-g-wall-fmessage-length=0

OBJS = sample.o SAMPLECLASS.O dllmain.o stdafx.o

LIBS =

TARGET = Sample.dll

$ (TARGET): $ (OBJS)
$ (CXX)-O $ (TARGET) $ (OBJS) $ (LIBS)

All: $ (TARGET)

# RM for Linux/unix, while del for DOS
Clean
Rm-f $ (OBJS) $ (TARGET)
Del *.o
Del Sample.dll

SAMPLE.DLL:SAMPLE.O SAMPLECLASS.O
g++-shared-o Sample.dll sample.o sampleclass.o-wl,--out-implib,libmessage.a

Sample.o:sample.cpp Sample.h SampleClass.h
g++-c-dfilterplugin_exports Sample.cpp

Sampleclass.o:sampleclass.cpp SampleClass.h
g++-C SampleClass.cpp

Dllmain.o:dllmain.cpp Sample.h
g++-C Dllmain.cpp

Stdafx.o:stdafx.cpp stdafx.h Targetver.h
g++-C Stdafx.cpp

VS2005 Project migration to eclipse CDT

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.