Dark Bit Factory & Gravity
PROGRAMMING => C / C++ /C# => Topic started by: hellsangel on January 06, 2008
-
yup
I see on the forum a post about the mixing of c/c++, but when it's main.c + functions.cpp : no problems.
But my problem is that the main is a c++ class, and the rest of program is C
strange thing happen :
when I made the project, after some fixes because of "stdafx.h" - the cpp use it as precompilated header, I desactived precomp header of each c files - at the first compilation I had the problem of lib conflict (libcmt, mscvrt) : "nafxcw.lib(afxmem.obj) : error LNK2005 operator new already defined in LIBCMT.lib" because some new/delete function was used, but not needed : I deleted them.
And the compilation was Ok : the program works fine.
And now the strange bug : If I close the project (vc6) and open it again, the error LNK2005 is back, but I've no more new/delete functions.
the first time it was a big chance, no ? now it doesnt work anymore if I dont remade all the project from scratch.
Is it possible to fix that ?
or to adapt the main class in C ?
thanks
-
That linker error is because you haven't used the same library settings for all the .libs/.obj files in your project.
The choices are 'dll', 'static', 'multithreaded dll', 'multithreaded static'. Also there are debug versions of these. Each project must use the same settings or not link to any runtime at all (/nodefaultlib in the linker options). If you choose dll then all of them may be linked against the dll runtime. If you choose static, then all modules should use /nodefaultlib except the main program.
I don't really know what you mean when you say that main is a c++ class.
Jim
-
thanks for you answer
the whole project is a plug in compiled as DLL in multithreaded
err, yes sorry for the mistake about "the class"
here is the source:
main.cpp
#include "stdafx.h"
#include "main.h"
#include <math.h>
#include "MainData.h" ; -> here is the main Class !
// create the MainData object using VTable : all exported functions of the plugin
extern "C" __declspec(dllexport) CMainData* CreateObject()
{
return new CMainData();
}
// specific plugin functions
extern "C" __declspec(dllexport) char* GetShortInfo()
{
return "name of plugin";
}
[...etc...]
// CMain construction
CMain::CMainApp()
{
}
// The one and only CMainApp object
CMainApp theApp;
main.h
class CMainApp : public CWinApp
{
public:
CMainApp();
DECLARE_MESSAGE_MAP()
};
maindata.cpp
#include "stdafx.h"
#include "MainData.h"
[...implementation of CMainData class...]
maindata.h
class CMainData
{
public:
CMainData(); // protected constructor used by dynamic creation
//******** VTABLE *************** here the exported plugin functions
public:
virtual int function1();
...
};
all cpp files have precomp headers set on StdAfx.cpp (StdAfx.h)
in this plugin project, I added my C program who have also exported functions
I verified the files, and all are "multithreaded"
difficult to explain. You can find the SDK and example I want to use (ColorWash) here (http://mmb.mediachance.com/files/mmbpluginsdk.zip)
I can perhaps send you by pm the files from the project if you want
-
I tried again, and It seems to be a VC6 bug. If I open the project without the .C files and add and fix them during the work session : all is ok
But no more after I close the project.
I'll try with another IDE (difficult because I dont know enough devcpp or others ide)
marvellous bug :xmas: