• Advertisement
Sign in to follow this  

How to make a dll of source that requires multiple compilation

This topic is 1665 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a source code that was written in C and therefore it uses a lot of macros as "templating" machanism. Although following code is C++ it illustrates this well:

#include <iostream>
#define IntType int
//#define IntType long
//#define IntType long long

#define CREATE_FUNCTION_NAME(it) function_for_it##_arg

#include "stdafx.h"


IntType CREATE_FUNCTION_NAME(IntType)(IntType x)
{
  return x*x;
}


int _tmain(int argc, _TCHAR* argv[])
{
    std::cout<<CREATE_FUNCTION_NAME(IntType)(2)<<std::endl;
    getchar();
    return 0;
}

My question is: How can I force Visual Studio (2010) to compile this for every required IntType and place all functions in DLL lib? In a standard manner I am able to create a project only for one IntType and get corresponding DLL. It is somewhat solution, but I would like to have all functions connected to this source in one DLL. Is it possible? A makefile project maybe? Example would be very useful.

 

Thanks in advance and Regards,

Miseryohmy.png

Share this post


Link to post
Share on other sites
Advertisement

Make the definition a macro and instantiate the macro with the desired types.

#define CREATE_FUNCTION_DEFINITION(IntType) \
IntType CREATE_FUNCTION_NAME(IntType)(IntType x) \
{ return x*x; }
 
CREATE_FUNCTION_DEFINITION(short)
CREATE_FUNCTION_DEFINITION(int)
CREATE_FUNCTION_DEFINITION(long)
...

I think you have to use a two-pass macro expansion to get the name-macro to expand correctly within the definition-macro, or just duplicate the name generation in the second macro manually, but the idea is what's important here.

Share this post


Link to post
Share on other sites

I don't think it will work in my case. I have a source code containing hundreds of files containing really a lot of code. The question is rather how to set up a VS project than how to expand a macro, Orginally an IntType is defined in a makefile, and it is compiled in several steps. My question is: if it is possible to obtain something similar from the IDE level.

Share this post


Link to post
Share on other sites

To set a preprocessor definition in the IDE go to project properties, C/C++, preprocessor and look at the preprocessor definitions line. 

Share this post


Link to post
Share on other sites

To set a preprocessor definition in the IDE go to project properties, C/C++, preprocessor and look at the preprocessor definitions line. 

I've tried that and it allows only to compile it for one type. So when DLL is built I get undefined reference to other in types. IDE would have to compile sources three times and place the code in one DLL.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement