7

I'm trying to start a C++ game engine project.

I don't have much knowledge of dll's and lib's but figured the engine itself would be a dll and I would have separate dll projects such as renderer, input, etc that would be used by the engine and the engine dll would be used by the game.

I seem to have the engine project referenced fine in the demo.exe project(by adding a reference and adding the path to additional include directories) but when trying to add a reference to a renderer dll project in the engine dll project I'm getting:

error LNK1104: cannot open file 'MyPath\Renderer.lib' MyPath\LINK Engine

Why is it mentioning libs?

LihO
  • 41,190
  • 11
  • 99
  • 167
EvilWeebl
  • 689
  • 1
  • 8
  • 16
  • possible duplicate of [How to make a .lib file when have a .dll file and a header file](http://stackoverflow.com/questions/9360280/how-to-make-a-lib-file-when-have-a-dll-file-and-a-header-file) – jww Nov 17 '14 at 06:53

4 Answers4

10

Many DLLs comes with corresponding LIB libraries, that are only needed at linking stage. So basically there are 2 types of LIB libraries:

  1. Real static library that contains all the object files

  2. Library with only definitions for the linker, this kind of libraries comes with DLLs

So basically you need to link this LIB file in order to be able to work with DLL

nogard
  • 9,432
  • 6
  • 33
  • 53
  • 2
    I cant find any .lib files being created anywhere. If I take for instance the renderer dll project that I want to include in my engine dll project. The renderer builds fine and outputs a *.dll, *.ilk and *.pdb into my (solution)/Debug folder. Also there are files in my(solution)/Renderer/Debug folder such as a *.obj. Where should I be linking to? Also when it eventually comes to making an install project will I just need the dll's or the linkers too? – EvilWeebl Mar 09 '13 at 17:10
  • In my case, the folder containing the *.obj files contains the *.lib as well, but the other projects can't find it there... – Mooing Duck Dec 03 '13 at 17:48
3

So I sorted my problem. As they were new projects they had no methods implemented yet, so no lib was being created, so nothing to reference to..silly me.

One last thing though, I'm having trouble defining the dllimport/dllexport macro for a header file. I'm trying to get it to define dllexport when its the exporting project but say my project is 2 names, e.g "awesome engine" then how do I realise the export macro that apparently is created automatically? Should I use an underscore for the space?

#ifdef AWESOME_ENGINE_EXPORTS // Or AWESOMEENGINE_EXPORTS?
#define DLL __declspec(dllexport)
#else
#define DLL __declspec(dllimport)
#endif
EvilWeebl
  • 689
  • 1
  • 8
  • 16
  • 1
    Right click the project, properties, configuration properties, C/C++, preprocessor. Add `AWESOME_ENGINE_EXPORTS` (or whatever your arbitrarily choose) to the list of Preprocessor Defines of your DLL. That makes the macro defined in your dll, causing the functions to be exported. Everyone else won't have that macro, so the functions will be imported. – Mooing Duck Dec 03 '13 at 17:55
2

Generally,

The library may give you it's APIs in two modes:

  • Dynamic: Smaller executable file, but needs its DLLs.

  • Static: Larger executable file, but stand-alone.

First of all, decide how do you want to use that library, statically or dynamically?! Then configure your project which the compiler be able to find header files of that library. Then if it's necessary add LIB files to your project.

In your case: Check if you added LIB files correctly to your project or makefile, or not?

masoud
  • 55,379
  • 16
  • 141
  • 208
  • I'm happy to do it dynamically, that way if I ever ship a game it will ship with the corresponding dll's meaning that its easier to update and mod if necessary. In which case my Renderer dll project isn't creating a lib file, only a dll, ilk and pdb file. I've just noticed when looking under the project references properties of my renderer(under the framework and references tab of engine properties) that it has an option for link library dependencies set to true, it seems to build if I set it to false but does that mean much? – EvilWeebl Mar 09 '13 at 17:26
2

the engine project referenced fine in the demo.exe project(by adding a reference and adding the path to additional include directories)

Some libraries can be linked statically, meaning that you need only header files (.h/.hpp) and .lib files. Other libraries might require dynamic linkage that will result into your program being dependent on some DLL files, but usually you will need to have header files to know what is in those DLLs anyway. Sometimes, which seems to be your case, you need all of them: header files, static libraries and DLLs.

Header files contain declarations, they define the structure of your classes, they declare prototypes of your functions, etc. Static libraries (.lib files) are binaries, that contain definitions of your functions, variables and so on, that need to be resolved at compile time, so when they are missing, the linker will complain. Dynamically linked libraries (DLLs) are binaries as well, but they are resolved at run-time, meaning that the time when you really need them is when you run your program.

LihO
  • 41,190
  • 11
  • 99
  • 167