How are we supposed to create a DLL, included with header files?
For example, a project using the raylib game library requires raylib.dll to be present with the output file.
The raylib.dll is included with the header files of the raylib game library.
Is that how are supposed to create a DLL and include header files into it?
I am using Dev C++ with a GCC compiler.
There's only a limited relation between the header files and the creation of the DLL. In particular, you use the word "linked", and header files are not linked. Header files are included, libraries are linked. Including happens before a compile, linking afterwards.
Header files can provide declarations for functions defined in the DLL. That tells the compiler that those functions actually exist (somewhere), so the compiler will ask the linker to find those functions. The linker in turn will find them in the library.
Related
I'm kind of a noob in these things.
I have a .cpp file that uses functions from a .lib library (and its relative .h header file). In CLion I manage to run the program fine, but I need to compile it as a .so library because I want to use the functions defined in the .cpp in a python program.
Do you guys know how to do it?
So, I made a dll and it compiles great.
Then I referenced this dll I made in another project and received this error message:
error C1083: Cannot open include file: 'openssl\ssl.h': No such file or directory
this .h file is used inside the dll, I would think that by referencing the dll I should not have to include this file directly...
Shouldn't a dll have all the files needed for it's purpose "inside it"?
Shouldn't a dll have all the files needed for it's purpose "inside it"?
No. A DLL contains machine code.
The main difference between .c and .h files is that .c files contain Code and .h files contain Headers (i.e. that's what they're supposed to, although they're not bound to). You need those header files in order for the compiler to know what to look for in the DLL. After your program has been compiled and linked, the header files are not required anymore.
That's why the authors of libraries written in C or C++ which are not open source usually provide precompiled binaries as well as header files.
A file format containing machine code and headers would be possible, but to my knowledge, no such format exists, and it would be really bad if it did, because for a lot of programs that would mean huge executable files.
No, because:
A .dll is a compiled, binary file that can be dynamically loaded at runtime by .exe programs.
A .h (or .hpp) file contains source code definitions of function prototypes or data structures for your C/C++ program, which are used during compilation.
To compile your source code, you'd need to:
#include the header file(s) so that the rest of your code knows what the data structures and function signatures stored in the DLL look like.
Link with the .lib or .a file equivalent of the .dll file.
If all goes well, then the .exe file generated by the compilation process will be able to dynamically load in and use the (already compiled) functions stored in the .dll file.
I have a small library project that uses OpenGL (glfw and glew). Now, the project compiles fine, but when I create a new project and statically link the library project, VS starts to throw errors in the library project. Why is that?
More specifically, I get this error:
error C1083: Cannot open include file 'GL/glew.h': No such file or directory (file: trenums3d.h)
The project setup is like this: There's the library project 'Foo', which is compiled into a static library ('Foo.lib'). The application project 'Bar' links 'Foo' (I added the folder where Foo.lib resides to Bar's 'Additional Library Directories', as well as the source folder of 'Foo' to Bar's 'Additional Include Directories'). If I compile only the library project, everything works just fine, but compiling the whole solution give me the aforementioned error.
This isn't a proper answer to your question, but just an explanation of the steps required for building an application in a compiled language.
Building a project containing multiple files is a three-step process:
Creation and editing of source and header files
Compilation of the source files (this step contains many sub-steps). This step creates object files of all translation units
Linking of all object files and libraries to form the final executable
Error like the one shown in your question is emitted in the second step. Linking with libraries happens in a completely different step, and is usually done by a different program than the compiler.
To answer your question, if linking with a static library also requires linking with the other libraries that the static library depend on, then the answer is normally yes. Static libraries only contain the function in the actual libraries, you can look at a static library more as a collection or archive of object files. Static libraries does not contain any information about other libraries they depend on.
And as for your problem, with the pre-processor error, it's because you include a header file from your static library, and that header file in turn includes some header files. But the pre-processor doesn't have the secondary included header files in its default search path, so you need to add it.
This still have nothing to do with linking any library, this is a pure pre-processor issue, and is handled in step two in my list above.
I suspect the header files of your static library look like somewhat this:
#ifndef SOMECLASS_H
#define SOMECLASS_H
#include "GL/glew.h"
// ...
#endif
If you include this header file from another library or application, the compiler will open this file and will see that it needs to open GL/glew.h as well in order to be able to "understand" the definition of your class.
This means you need to supply at least the header files of glew. The only way to get rid of this is if you manage to only reference glew files from your .cpp files but not from your .h files. In some cases, forward declarations can be used, but not sure if this will work for glew.
Concerning the linker settings: In case your glew library is built statically as well, you may or may not have to supply that library file and link to it from your project. This depends on how you setup your linker for your own static library. If you have troubles in this step, create a new question.
I'm planning to use id3lib in my application. I'm looking for a way to use the library as a DLL. I've noticed that they released the library in various form: one of which is windows binary. My target platform in Windows, and I'll use Qt 4.8. After I extract the files in windows binary, I found the following files in Release folder:
id3lib.dll
id3lib.exp
id3lib.lib
I know how to use a DLL in Qt given the DLL, one or more header files where function prototypes resides, and with or without the *.lib file. This package doesn't come with a header file.
How am I supposed to use this package without any header file? What's the purpose of the *.lib and *.exp files here? As far as I know *.lib files are used for static linking with functions which I don't want in my program.
You've just missed the header. It is available under the include subfolder (see here), also the .lib file is still needed for linking, even if you'll be using the DLL.
The usual course is to use a header file #included in the C++ file, the .lib file to link to and the .dll is required at run time.
The header file should/may be in another package as the same header is probably used for different kinds of linking strategies.
At worst you should be able to use a tool such as depends.exe to view the exported symbols and create your own h file to match - but it would be better to find a .h file issued with the release.
I have a static library file (.a file), which I linked in my program. I included the header file for using the library. As far as i know if i link a library i dont need the implementations, because they are all compiled in the library file. But the header file of the library includes the some other header files. Should i need the c files for the function definitions declared in 'other' header files?
If the source has been compiled into the library, no. If the source for these headers has been compiled into some other library, you will need to link against that library. Otherwise, yes.
What does the documentation for the library say? Some libraries do
require others: these have to be installed, and you have to add the
appropriate -I, -L and -l options when compiling and linking. But
it's quite possible that the library itself defines several headers, and
that the includes you are seeing are just for other parts of the
library. Only the library documentation can tell you which it is.