I am trying to install the MySQL C++ Connector on my Mac. I downloaded the tar.gz file from mysql.com, and when I unzip it, I have three text files, one of which is a Readme that doesn't provide much help. Then there is the /include folder which has two C++ header files and then a sub-folder called /cppconn that has another 14 C++ header file. Then there is also the other folder call /lib that contains a Dynamic Library file and two symbolic links to that Dynamic Library file, as well a a .a file. I was wondering where I place these files or folders on my Mac so that I can write a C++ application that can connect to a database? Or if there is a way for gcc or g++ to be able see these files in a location I specify when compiling? Any help would be much appreciated.
I don't know mac specifics, but usually (in linux / unix / windows - I dont expect mac to be any different) you either
put the header files into some place that is in your compilers header path(such as /usr/include), library files in your compilers lib path (such as /usr/lib),
or
you put them anywhere you like (perhaps /usr/local/my_cpp_connector) and then add that path to your compilers search path, both for headers and libraries.
You could also do like
/usr/local/my_cpp_connector/include
/usr/local/my_cpp_connector/lib
but I guess you got the idea at this point.
Related
I haven't used online libraries before this.
I just downloaded libzip from https://libzip.org/ (was looking for c++ file to unzip zip files)
I now have this nice folder that's called libzip-1.5.2.
Where do I put it? I'm using mingw to compile, and just emacs to write.
I've tried copy and pasting it into mingw's various bin folders, lib folders, include folders, etc. A great variety of places within the C://mingw root folder. None of them work.
No matter where I look, every single question glosses over this, just saying "just include zip.h" but never mentioning how to actually set it up.
I guess this could be generalized to: I have a bunch of .c and .h files from a library I downloaded for my compiler. Where do I put them so that I don't get:
"fatal error: header.h No such file or directory"
Again, I use MinGW/G++ to compile, and just Emacs for writing. I'm running Windows 10.
Put it somewhere with an simple pathname. You have to tell g++ where to find the libraries and the headers. Normally this is done with the -L and -I option. Maybe you have to compile the library first. There you have to look at the install instructions.
I am a Python developer and I have not used C++ since university. I am doing scientific programming with python, mainly. I wanted to try C++ to see if it is better performance-wise.
I am quite new in C++. I have found dlib library, which seemed a good library as it had many interesting features. But when I downloaded it, I found several folder full of .h and .cpp files.
In Python, I would have installed a wanted library using pip or something, then use it in my project using import.
Is there a similar installation for c++ libraries? Or do I have to look among all those .h and .cpp files and decide which ones I need in my project then copy them? Or how do I use the dlib library?
I have searched a lot on google but I could not find any indication on how to use a c++ library or install a new package to be used.
I use Visual Studio Community 2017 and Windows 10 if that matters.
To integrate a library, you need two kinds of things:
header files (usually *.h) with the declarations required to let the compiler know about the features in the library (a little similar to an import statement);
compiled library files (usually *.lib) containing the precompiled executable code itself, to let the linker assemble the final executable file.
In some cases (especially for templated code), a library can be made of header files only. In other cases, the package doesn't contain a ready-made library file and you have to build it yourself or manually include the source files (*.c/cpp) in your project.
Not speaking of the innumerable optional settings that you may have to adjust to comply with the specifics of the generated code, such as function calling convention, struct alignment...
Last but not least, some libraries are connected to at run-time only. They are called Dynamic Link Libraries and involve yet different procedures.
All of this is relatively complex and close to black magic for beginners. If you are very lucky, you will find some library documentation telling you which options to use for your compiler. If you can, start from an existing sample project that works!
For dlib, check http://dlib.net/compile.html.
Be ready for a cultural shock when you will compare to the ease of use of the Python modules.
It is quite a broad question, but I'll do my best.
First of all, in C++ libraries consist of header files and precompiled part (.lib,.dll on Windows, .a, .so on Linux). To use them in your project you have to inform your program (and compiler) about features that library has (by #including their header file) and linker to include that library binaries.
pip is package manager, which automatically downloads, builds and installs library that you want in your system. In C++ there is no such single tool at the moment and there steps must be done more or less manually.
For dowloading you usually end up with git or downloading the zip archive with source (do it here). Once you have sources you have to build it.
In order to achieve multiplatformity libraries usually does not get shipped with concrete build system description (Visual Studio Project on Windows or makefile on Linux etc.), but are created in more general tool CMake, which abstracts them. E.g. dlib does that. With use of CMake (For start I recommend CMake-GUI, which is installed with CMake on Windows) you can generate Visual Studio Project, which later you can open and compile to generate .lib file. How exactly to do it follow dlib compilation description.
Once you have you lib and headers files on your disk you can add headers and .lib to your Visual Project and use as any other C++ library. (Seems old, but should work)
As far as I know, there are no tools similar to pip for C++. What you have to do depends on your working environment and the respective library.
In case of dlib there are instructions on the project homepage for Visual Studio. Basically, it involves compiling the whole library alongside your own project by copying a single source file to it and setting up include pathes.
From http://dlib.net/compile.html:
Compiling on Windows Using Visual Studio 2015 or Newer
All you need to do is create an empty console project. Then add dlib/all/source.cpp to it and add the folder containing the dlib folder to the #include search path. Then you can compile any example program by adding it to your project.
Again, note that dlib will only be able to work with jpeg and png files if you link in libjpeg and libpng. In Visual Studio, the easiest way to do this is to add all the libjpeg, libpng, and zlib source files in the dlib/external folder into your project and also define the DLIB_PNG_SUPPORT and DLIB_JPEG_SUPPORT preprocessor directives. If you don't know how to configure Visual Studio then you should use CMake as shown above since it will take care of everything automatically.
You have to download them, put them in your project directory, and then include them almost the same way you would do in python. You need to include only the .h files.
Example for test.h:
#include "test.h"
Hope this helps!
I'm new to programming and wanted to check this program called primesieve. http://primesieve.org/
I have windows 7 with codeblocks ide.
I tried searching for a way to execute the program but couldnt find anything useful.
I have never added a library (is that called a library?) before so please help.
similar:
Installing c library in codeblocks
cant install GMP library in codeblocks
You should have received a .h (or .hpp) file and a .lib file, most likely with the names primesieve.h (or primesieve.hpp) and primesieve.lib (or something similar).
If you didn't receive those files in your download, then you may have to download the source. It should definitely have the .h/.hpp file, but it's possible you'll need to generate the .lib file yourself. There should be instructions for your system.
You need to include the .h/.hpp file in your source code. You need to link against the .lib file. This part is described in the articles you linked.
I have no problems with LuaJIT, it great and easy to switch from good old Lua.
But for now i use folder src from LuaJIT distribution as include for lib.
It is kinda messy because there are makefile, batch scripts, c files, dasc files, src/jit folder with scripts which i know used with luajit.exe e.t.c.
I want to create clean include folder with only h files (and other if needed) for using LuaJIT in c++ windows application as shared lib, but quite don't know what to exclude.
My current exclude list
host folder
jit folder
c files
dasc files
c files
luajit.lib - goes to lib folder
luajit.exp
luajit.exe
luajit.dll - goes to bin folder
makefile
makefile.dep
bat files
http://luajit.org/install.html
It's strongly suggested to build LuaJIT separately using the supplied build system. Please do not attempt to integrate the individual source files into your build tree. You'll most likely get the internal build dependencies wrong or mess up the compiler flags. Treat LuaJIT like any other external library and link your application with either the dynamic or static library, depending on your needs.
Build as usual and then copy into your project the files:
lua.h, lauxlib.h, lualib.h, luajit.h, luaconf.h;
libluajit-5.1.a, or luajit-5.1.dll, or libluajit-5.1.x.x.x.dylib or whatever your platform static/shared library file looks like;
#include headers in project sources and link executables to the library file;
LuaJIT is ABI compatible with Lua, so the regular Lua headers will also work with LuaJIT. The only headers you need are lua.h, luaconf.h, lauxlib.h, and lualib.h. LuaJIT also comes with luajit.h, but it's not required, and doesn't contain anything that isn't accessible via the jit library.
What I am trying to do is exactly like the instructions on this website:
http://www.cprogramming.com/tutorial/sdl/setup.html
The only problem is that I didn't download the version of Code Blocks that comes with the mingw32 compiler. I got the latest release from http://www.equation.com/servlet/equation.cmd?fa=fortran and installed it in 'C:\gcc'. So, the folders that it is asking me to move files into don't exist.
The article asked me to download this file:
SDL-devel-1.2.15-mingw32.tar
Then in that file move the 'include\SDL' folder into the 'C:\Program Files\CodeBlocks\include'. (I don't have a CodeBlocks\include folder)
It then asked me to move the 'SDL.dll' to 'C:\Windows' which I was able to do.
Finally it wanted me to copy the contents of the 'lib' folder into the 'CodeBlocks\lib' folder. (Another folder I don't have because I installed my compiler separately from the Code Blocks install)
Since I installed my compiler at 'C:\gcc' I tried to add the files into the 'C:\gcc\include' and 'C:\gcc\lib' files, but that didn't work.
I am not very familiar with the process of using 3rd party libraries. I usually use Java where you can just stick the .jar file in with your code. Do I need the .dll, include, and lib files. Where do I actually need to put them? I would also appreciate knowing why as well?