Is there a general way of linking nativly?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Imbrondir
Posts: 6
Joined: Fri Jun 29, 2007 1:36 pm

Is there a general way of linking nativly?

Post by Imbrondir »

This is kind of off topic, but it is a general c++ programming issue. Irrlicht is one of the very few libraries I have managed to link with. I have tried to link with a lot of open source 3rd party libraries though. My consistent low success has lead me to believe that I'm missing something. Is there a general recepie for using 3rd party libs?

I'm using visual studio.net 2003. And so far I've thought it works like this:
1) Project properties - c++ - additional include directories - Add path(s) to .h files
2) Project properties - linker - additional library directories - Add path(s) to .lib files
3) Project properties - linker - input/additional libraries - Add specific .lib files I want to use. Or use a #pragma comment(lib, "specific.lib")
4) Begin to use classes freely with a #include <specificHeader.h> in top of my header files.

This seem to work sometimes, but mostly not. Examples are python, lua, squirrel, boost and xulrunner.

Some random questions:
- In the case of python, it's a static lib that I think is compiled with the vs2005 compiler, in that case my compiler would not be compatible with those libs correct?
- What is interface definition language (.idl files)?
- How come some times using #pragma comment(lib, "specific.lib") sometimes doesnt work but needs to be put in the 'input' tab of project linker properties?
- Are such problems in native libraries supposed to be hard to figure out, and specific to each new project?
- In the case of the above mentioned recepie working, I always get a warning for multiple interfaces. Meaning for each MyClass::foo(), I get a MyClass::foo() already defined, ignoring second declaration. For larger libraries, this can mean 1000s of warning messages which adds a very annoying time (printing 2000 lines takes time) before the executable is linked. Any idea of why this may be happening?
CuteAlien
Admin
Posts: 10035
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

The way you described seems to be fine. Which errors do you get?
There is one important difference between static and dynamic libraries (dll's). For dynamic libraries you only link to a so called import library which only contains a table with addresses which will be filled at runtime with the functions from the dll. But in that case you get a runtime error message about missing dll's.

Sometimes it's a problem that different libraries are using different standard c libraries. Usually the easiest thing is to compile them all with the same settings (use multithreaded dll and multithreaded dll debug unless you have a good reason not to do so),

About the questions:
- I'm not sure, but I would expect that the c++ ABI (application binary interface) between vs2005 and vs2003 was not changed. So it should work.
- You shouldn't need idl files. Once more I'm not exactly sure, but I think you need those mostly when working with COM. They are something like language independent header files. So you can describe types and thereby exchange variables.
- Not sure why the pragma sometimes does not work. I never use it. It's maybe fine for the irrlicht examples, as it allows to tell which libs to link without having to distribute the project file. But I prefer it a lot to keep linking and compiling separate and also to keep stuff platform independent so I never use that pragma.
- Problems are by definition hard to figure out ;-) But yeah - I also sometimes have to fight, especially if each library has some more dependencies. It generally helps to read the error messages and the library documentation.
- That sounds like you try to link the standard libraries (clib) with different settings. See my answer above.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply