tags:

views:

371

answers:

5

Is there a way in my code that I can link to the library files I need so that I do not have to setup each individual compiler I use?

I want to be able to use Visual C++.net 2005, G++, etc. I am trying to make a cross platform game engine, but some platforms use a custom compiler and I want to make my engine as versatile as possible.

A: 

I know that Visual C++ has the #pragma comment line. Not sure if others do.

#pragma comment(lib, "SomeLib.lib")

What you might want to look at is like Scons. http://www.scons.org/wiki/FrequentlyAskedQuestions#head-00ce208eece451fe9879c6f8dd1c45b56f4c76d1

Daniel A. White
A: 

I think this will help you:

#ifdef _DEBUG
#   pragma comment( lib, "dir1/dir2/mylibd.lib" )
#else
#   pragma comment( lib, "dir1/dir2/mylib.lib" )
#endif

Edit: probably g++ does not support linking through code. Daniel suggested makefiles and that would be a good choice.

Nick D
I do not think that is cross-compiler.
Daniel A. White
Yes you are right.
Nick D
+2  A: 

There is a tool called mpc that can create both makefiles and VC projects from the same mpc DSL. If you would use that tool you would specify the link dependencies (libraries) once in the pmc files and it would generate makefiles for g++ and project files for Visual Studio that contain the necessary information on how to link your libraries.

From the mpc homepage:

supports multiple versions of make (GNU, Microsoft, Borland, Automake), Visual C++ 6.0 and Visual Studio 2003, 2005 and 2008.

lothar
+1  A: 

I don't fully understand your problem sure there is a way to specify your libraries in UNIX via -L dir option for visual C++ it seems that you can use /LIBPATH to override the environment library path.

I doubt you would want to do it in your code as the library path is often not static same as header files.

You would want to create a custom make file setting up the correct compiler options and paths for the different platforms and tools you are using. seems that is what the mpc tool that was suggested is trying to accomplish.

AndrewB
A: 

Qt's qmake sounds similar to mpc. You define the projects and parameters in the .pro files, then qmake creates a Makefile or Visual Studio project file.

This is one of the pains of cross-platform development, but the good news is that the required library list usually doesn't change all that often.

Michael Mathews