How do I manually import .h files into the system library? - mysql

I have some C code that #includes the file <mysql/mysql.h>. I am running on a Mac, and cannot figure out how to get mysql installed (after running the solution found on SO, the mysql directory does not even exist in the system library). I was able to download MySQL from the source code, and now I have a mysql.h file-- in the "include" directory of the source code.
However, moving this file into the system library alone will obviously not make my program work. I expect that I need to compile the library (which I've done), and to move the binary file somewhere, in order to be linkable to my program.
As per #RustyX's suggestion, I installed the Mac MySQL package. That put a copy of mysql.h into the /usr/local/mysql-5.7.19-macos10.12-x86_64/include/ directory. However:
1) I am using gcc to compile the .c file. I am not sure how to configure gcc to include the directory in question. I tried
-L(directory path)-- both for the installed Mac MySQL package, and the MySQL source code I downloaded-- but I get the following error:
ld: library not found for -lmysqlclient
Is there another path I would include for mysqlclient? Or another package to install?
2) Even if I do include it, it will still not find the file since the called-for filename is <mysql/mysql.h>, and the filename it will find is <include/mysql.h>. Since the file is used by others, is the best course of action here to rename the include directory to mysql? Or to change the path in the .c file, and then change it back every time before committing?

Have you tried a statement like this,
#include <mysql.h> //in your program
To compile and run
gcc -w -c -g -I/usr/include/mysql filename.c
gcc -o filename filename.o -L/usr/lib64/mysql -lmysqlclient
./filename (input params)

Related

How to specify include directory of mpicxx in the command line option of make?

I am trying to build all CUDA samples by running make in the sample's base folder. One of the samples require mpi.h, but the system did not have it, which causes an error:
make[1]: Entering directory '$HOME/cuda_samples/samples/0_Simple/simpleMPI'
/bin/mpicxx -I../../common/inc -o simpleMPI_mpi.o -c simpleMPI.cpp
simpleMPI.cpp:25:10: fatal error: mpi.h: No such file or directory
25 | #include <mpi.h>
| ^~~~~~~
compilation terminated.
make[1]: *** [Makefile:371: simpleMPI_mpi.o] Error 1
Since I don't have root privilege, I downloaded a deb file for libopenmpi-dev package (using apt-get download command) and extracted it to somewhere in my user space (using dpkg -x command). However, as we can see, mpicxx tries to find mpi.h in ../../common/inc, which is not where I installed libopenmpi-dev in my user space (I did not notice that untill I installed the package. My bad). So I need to somehow tell mpicxx to find mpi.h in another directory. I know there is a -I option to tell make where additional include directories are, but this option does not apply to mpicxx. How to pass directory information from make's command line to mpicxx is beyond my knowledge. Can you please teach me what option I should use in make's command line to specify include directory used by mpicxx? Of course I can manually copy the installed libopenmpi-dev package to ../../common/inc to accommodate original settings in CUDA sample, but I would like to do something cool and learn something new, so I ask here. Thank you in advance for teaching me.
Environment:
Remote Linux with core version 5.8.0. I am not a super user.
CUDA version: 11.2
CPU: Intel Core i9-10900K
gcc version: (Ubuntu 10.2.0-13ubuntu1) 10.2.0
make version: GNU Make 4.3, Built for x86_64-pc-linux-gnu
MPI version: 4.0.3
The include directory in Makefile is held in a variable INCLUDES, together with -I. So, if we can somehow transfer the include directory of mpi installed in my user space to this variable, we are done. So, the question is reduced to how to transfer a user-defined value from make's command line into Makefile's variable and override it if it has be defined, as is clearly asked in the question.
Fortunately make provides this command line option: VAR=value, so the option to answer my question is
make INCLUDES=-I/path/to/mpi/include/in/my/user/space

compiling caffe with cudnn installed in HOME directory(without root priviledg): cannot find lcudnn

recently came across a problem when compiling caffe on a server, prompts /usr/bin/ld: cannot find -lcudnn
since I don't have root priviledge, I installed CUDA-8.0 in my HOME directory, then download the libcudnn7-dev and manually do dpkg-deb -xv libcudnn-dev*.deb to extract the deb pkg, then I go to the lib directory, then run ar -x libcudnn*.a and gcc -shared *.o -o libcudnn.so, then copy the generated libcudnn.so to ~/cuda/lib64, then add the ~/cuda/lib64 to the LD_LIBRARY_PATH, but the error prompts, I don't know how to fix this, can someone help?
And I don't understand why it is /usr/bin/ld: cannot find -lcudnn, not something like LD_LIBRARY_PATH/=: cannot find -lcudnn
EDIT:
I downloaded the .tgz file and follow the install guide instructions to install cudnn, but it still prompts the error, my ~/.bashrc is configured:
export CUDA_HOME="~/cuda"
export PATH="/home/wangtao/anaconda2/bin:$CUDA_HOME/bin:$PATH"
export LD_LIBRARY_PATH="$CUDA_HOME/lib64:$LD_LIBRARY_PATH"
I find the /etc/ld.so.conf is like this :
include /etc/ld.so.conf.d/*.conf /usr/local/cuda-7.0/lib64
it is not my wanted path of ~/cuda/lib64, but don't know how to modify it since I don't have root priviledge on the server, I have compiled successfully on local machines, but this seems to be hard
We newbies need to learn more, maybe other people sometimes would not help you much, help yourself, learn more!
Turns out that linking is different from dynamic loading, linking done pre to dynamic loading, what LD_LIBRARY_PATH can affect is dynamic loading, which gives the library file path(eg, .so.1.0, not .so which is usually a symlink to .so.1.0 stuffs and is used for linker not loader), so adding the libcudnn.so path to LD_LIBRARY_PATH does not help, what /usr/bin/ld complains is that linker cannot find the cudnn library, so we need to add libcudnn.so path for the linker to find it, which is what LIBRARY_PATH cames to help, just add it to it, then linker can find it, sometimes we are just not on the right direction, do not annoying, just learning more:)

Sphinx 2.0.4 Install Error with MAMP 2.0: Can't Find MySQL Headers

Developing locally in MAMP and need Sphinx to work with MAMP's MySQL. Basically hitting a dead end during $ sudo make.
MAMP installs without some necessary resources for Sphinx integration, mainly a mysql lib directory and an include directory filled with C header source files. These were downloaded and installed successfully (using CMake) into the following directories:
/Applications/MAMP/Library/include/mysql
/Applications/MAMP/Library/lib/mysql
After unzipping Sphinx and running:
sudo ./configure --prefix=/usr/local/sphinx --with-libstemmer --with-mysql=/Applications/MAMP/Library
I got:
******************************************************************************
ERROR: cannot find MySQL include files.
Check that you do have MySQL include files installed.
The package name is typically 'mysql-devel'.
If include files are installed on your system, but you are still getting
this message, you should do one of the following:
1) either specify includes location explicitly, using --with-mysql-includes;
2) or specify MySQL installation root location explicitly, using --with-mysql;
3) or make sure that the path to 'mysql_config' program is listed in
Changing the ./configure command to:
sudo ./configure --prefix=/usr/local/sphinx--with-libstemmer --with-mysql-includes /Applications/MAMP/Library/include --with-mysql-libs /Applications/MAMP/Library/lib
throws the following on the outset, but regardless results in a successful configuration:
configure: WARNING: you should use --build, --host, --target
configure: WARNING: invalid host type: /Applications/MAMP/Library/include
configure: WARNING: you should use --build, --host, --target
configure: WARNING: invalid host type: /Applications/MAMP/Library/lib
The log also has the following line, (which I think is relevant in a sec):
checking MySQL include files... -Iyes
Now, continuing, $ sudo make throws the following:
Making all in src
/bin/sh svnxrev.sh ..
make all-am
g++ -DHAVE_CONFIG_H -I. -I../config -DSYSCONFDIR="\"/usr/local/sphinx--with-libstemmer/etc\"" -DDATADIR="\"/usr/local/sphinx--with-libstemmer/var/data\"" -I/usr/local/include -Iyes -Wall -g -D_FILE_OFFSET_BITS=64 -O3 -DNDEBUG -MT sphinx.o -MD -MP -MF .deps/sphinx.Tpo -c -o sphinx.o sphinx.cpp
In file included from sphinx.cpp:16:
sphinx.h:64:19: error: mysql.h: No such file or directory
... //whole bunch of errors follow, resulting from the above
So, I know mysql.h exists in my includes file, I think I have all necessary binaries as well, and the configuration seems to see the include files so I'm tearing out my hair a bit. I'm hoping this is a simple path problem, or a syntax error on my part with the ./configure attribute since this is my first time compiling and installing from the command line.
Thanks.
Sphinx's ./configure uses an unknown default value for --with-mysql, which is enabled by default, which could make you think calling it is not necessary.
To get Sphinx to work with MAMP's varyingly distributed MySQL files, make sure to use each of the following attributes in your ./configure command, specifying direct paths for each:
--with-mysql= // root mysql app
--with-includes= // path to mysql header includes
--with-mysql-libs= // path to libmysqlclient.dylib files
The final command that worked for me:
./configure --prefix=/usr/local/sphinx --with-libstemmer --with-mysql=/Applications/MAMP/Library --with-mysql-includes=/Applications/MAMP/Library/include/mysql --with-mysql-libs=/Applications/MAMP/Library/lib/mysql
--prefix is your preferred install directory in usr/local and --libstemmer adds Snowball's extended stemming functionality (if you downloaded it).
If this runs without error, just make and make install and you're good to go.
Also note that there's a configure error log in the uncompressed Sphinx directory that's easy to overlook. Didn't help in this scenario, but could be really useful to others if you're having problems.

Problem compiling C program that interacts with MySql db

I have a problem compiling a program written in C which should interact with a MySql db.
I'm using Ubuntu 11.04.
I type this:
gcc -o magazzino main_magazzino.c -L/usr/lib/mysql -lmysqlclient
and I get this error:
main_magazzino.c:4:25: fatal error: mysql/mysql.h: No such file or directory
compilation terminated.
-L and -l are only relevant in the linking phase, and the program already fails to compile.
Check that /usr/include/mysql/mysql.h exists. If you have installed the header files somewhere else (say /opt/mysql/include), add that location with -I/opt/mysql/include.
you need to install mysql c connector.
you can download from http://dev.mysql.com/downloads/connector/c/
after downloading you can specify header include path using -I option.

Equivalent to libmysqldev FreeBSD

I have compiled a program in fedora using the mysql dev library (include mysql.h in header file). I need to compile in on FreeBSD. I do not want to download from source and compile but rather would like to download from ports or something equivalent to facilitate removing it if need be.
Does anyone know the equivalent of the libmysql-dev in FreeBSD. I have not found it in ports?
You do not need a special package for this. The standard mysql client package/port already includes the libraries and the header files you will need. The header files will end up, by
default, in /usr/local/include/mysql/ directory, while
the libraries will go to /usr/local/lib/mysql/.
So - just install a client from ports or packages, and you are set.
mysql.h is included in the mysql-client-xx port.
assuming you have a configure script or makefile you should set the LDFLAGS and CPPFLAGS environment variables to:
export LDFLAGS='-l /usr/local/lib'
export CPPFLAGS='-I /usr/local/include'
(or setenv, if using csh)
then ./configure and make as normal.
if you are compiling from the command line "gcc -o myprog mysource.c" just add the -I and -l options to your command and it should compile fine.
try: find /usr/local -iname 'mysql' to see files (headers, shared objects and binaries) you in fact have installed on your system.