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?
Related
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.
I am learning how to compile libraries and want to compile the fltk library for example.
To compile a static library I need .h and .c files and just compile them, but the library has not only many .h and .c files, but some other files I don't know what to do with them. In a folder called "src" with .c files there are some .h files, .xbm, .xpm, .fl and etc. including "Makefile" that maybe can help me I suppose.
So, how to do it right?
How about using the build system that came with the library?
Sounds like it's expecting you to run make.
But even if it was using something else, like CMake or SCons, it still seems like the best option would be to just use what it expects rather than trying to import it into some other build system.
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'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 problem, I'm working on a C++ project (I'm using Eclipse as my IDE).
Now I want to make use of a C/C++ library, for example libcurl, so I download curl and don't know what to do next.
Must I only include the .h and .c files I need or must I compile it before?
A typical way to use a library (this, of course might differ from library to library) is to include all of the header files from the library, include them as needed, use functions that they provide. Then, when building the application, link the objects with the library object (.a, .lib, whatever the extension). If you don't have the .a or .lib file, then you should build that independently
You must compile it before, then include the h files in your include path (in the Eclipse project). You will also need to find out how to import the library that you compile into your Eclipse project.
Once all that is done, you can make calls to the library after #include'ing the appropriate headers.
Both ways are possible. Compiling to a library is probably easier.