Problem compiling C program that interacts with MySql db - mysql

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.

Related

Pass mysql.h path to gcc compiler

I've created a database using mysql, and now i need to connect it with C, basically just to call some functions, already created in SQL.
I've installed the "C Connector" from mysql website. When i try to compile my program using
gcc db.c i have this error:
db.c:2:19: fatal error: mysql.h: No such file or directory compilation terminated.
So, looking on the forum I understood that i need to include 'mysql.h' path when i compile my program, using -I, but it stills gives me an error.
The path where is mysql.h is the following:
C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include
Any idea?
You can try this:
gcc db.c -l mysql
That is usually how you compile programs with libraries such as this. if that does not work, try following this link:
https://dev.mysql.com/doc/refman/5.7/en/c-api-building-clients.html

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

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)

Error during the installation of Cython

I have installed SimpleCV 1.3 powerpack in my Windows 8.1. Then i set up the required path. And then i installed pyreadline, PIL, pip, ipython via cmd. But when i tried to run easy_install cython, i'm getting the following error,
C:\Users\Ankit>easy_install Cython
Searching for Cython
Reading http://pypi.python.org/simple/Cython/
Best match: Cython 0.22
Downloading https://pypi.python.org/packages/source/C/Cython/Cython-0.22.tar.gz#
md5=1ae25add4ef7b63ee9b4af697300d6b6
Processing Cython-0.22.tar.gz
Running Cython-0.22\setup.py -q bdist_egg --dist-dir c:\users\ankit\appdata\local
\temp\easy_install-lvjvzj\Cython-0.22\egg-dist-tmp-aeuxtq
Unable to find pgen, not compiling formal grammar.
Compiling module Cython.Plex.Scanners ...
Compiling module Cython.Plex.Actions ...
Compiling module Cython.Compiler.Lexicon ...
Compiling module Cython.Compiler.Scanning ...
Compiling module Cython.Compiler.Parsing ...
Compiling module Cython.Compiler.Visitor ...
Compiling module Cython.Compiler.FlowControl ...
Compiling module Cython.Compiler.Code ...
Compiling module Cython.Tempita._tempita ...
warning: no files found matching '*.pyx' under directory 'Cython\Debugger\Test'
warning: no files found matching '*.pxd' under directory 'Cython\Debugger\Test
warning: no files found matching '*.pxd' under directory 'Cython\Utility'
Scanners.c
C:\Python27\include\pyconfig.h(227) : fatal error C1083: Cannot open include file: 'basetsd.h': No such fil
e or directory
error: Setup script exited with error: command '"C:\Program Files (x86)\Microsof
t Visual Studio 9.0\VC\BIN\cl.exe"' failed with exit status 2
Please help me out.
I'm using a double partition system Windows8/Xubuntu14.04LTS.
I had the same issue when attempting to install Cython onto Xubuntu via pip.
So I installed Cython with below command and and everything went ok.
bashsh $ sudo apt-get install cython
This is not the best fix. But, may worth a trial if you are really
looking to port an almost complete project to Windows8.
You compile your Python main (without main):
bash $ cython --embed -o prog.c prog.py
You may decide to install Mxe (MingW) gcc on linux and do
cross compiling or, as me, to compile directly in the windows8:
bash $ gcc -Os -IC:\Python27\include -LC:\Python27\libs -o prog.exe prog.c -lpython27 -DMS_WIN64
Hope this might be of any help.

How to install RMySQL package for Windows?

Since binary file of RMySQL package is not available, I am not able to install it on Windows.
I looked up internet. I found this link. http://www.ahschulz.de/2013/07/23/installing-rmysql-under-windows/comment-page-1/#comment-3123
I followed the instructions, but I am getting an ERROR.
This is the final output I get after
>install.packages('RMySQL',type='source')
Installing package into ‘C:/Users/admin/Documents/R/win-library/3.0’
(as ‘lib’ is unspecified)
also installing the dependency ‘DBI’
trying URL 'http://cran.rstudio.com/src/contrib/DBI_0.2-7.tar.gz'
Content type 'application/x-gzip' length 194699 bytes (190 Kb)
opened URL
downloaded 190 Kb
trying URL 'http://cran.rstudio.com/src/contrib/RMySQL_0.9-3.tar.gz'
Content type 'application/x-gzip' length 165363 bytes (161 Kb)
opened URL
downloaded 161 Kb
installing source package 'DBI' ...
package 'DBI' successfully unpacked and MD5 sums checked
R
inst
preparing package for lazy loading
Creating a generic function for 'summary' from package 'base' in package 'DBI'
help
installing help indices
building package indices
installing vignettes
testing if installed package can be loaded
arch - i386
arch - x64
DONE (DBI)
installing source package 'RMySQL' ...
** package 'RMySQL' successfully unpacked and MD5 sums checked
checking for $MYSQL_HOME... C:\Program Files\MySQL\MySQL Server 5.6\
cygwin warning:
MS-DOS style path detected: C:\Program
Preferred POSIX equivalent is: /cygdrive/c/Program
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
test: Files\MySQL\MySQL: unknown operand
** libs
Warning: this package has a non-empty 'configure.win' file,
so building only the main architecture
cygwin warning:
MS-DOS style path detected: C:/PROGRA~1/R/R-30~1.1/etc/x64/Makeconf
Preferred POSIX equivalent is: /cygdrive/c/PROGRA~1/R/R-30~1.1/etc/x64/Makeconf
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
gcc -m64 -I"C:/PROGRA~1/R/R-30~1.1/include" -DNDEBUG -I"C:\Program Files\MySQL\MySQL Server 5.6\"/include -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall -std=gnu99 -mtune=core2 -c RS-DBI.c -o RS-DBI.o
**Syntax error: Unterminated quoted string
make: [RS-DBI.o] Error 2
ERROR: compilation failed for package 'RMySQL'***
removing 'C:/Users/admin/Documents/R/win-library/3.0/RMySQL'
Warning in install.packages :
running command '"C:/PROGRA~1/R/R-30~1.1/bin/x64/R" CMD INSTALL -l "C:\Users\admin\Documents\R\win-library\3.0" C:\Users\admin\AppData\Local\Temp\RtmpMvp14B/downloaded_packages/RMySQL_0.9-3.tar.gz' had status 1
Warning in install.packages :
installation of package ‘RMySQL’ had non-zero exit status
The downloaded source packages are in
‘C:\Users\admin\AppData\Local\Temp\RtmpMvp14B\downloaded_packages’
I have written the error i am getting in bold. Please help me resolve it.
Thanks a lot.
Go to System->Advanced->Enviroment Variables, press New and Enter
Variable name as MYSQL_HOME and Variable values as C:/Program
Files/MySQL/MySQL Server 5.6/, and notice that it is "/" not "\"
Copy C:/Program Files/MySQL/MySQL Server 5.6/lib/libmysql.dll to
C:/Program Files/MySQL/MySQL Server 5.6/bin and create C:/Program
Files/MySQL/MySQL Server 5.6/lib/opt folder and copy C:/Program
Files/MySQL/MySQL Server 5.6/lib/libmysql.lib to the opt folder
Run install.packages('RMySQL',type='source')
In some instances you might need to restart your PC.
Please following the instruction here: http://biostat.mc.vanderbilt.edu/wiki/Main/RMySQL
I believe you missed the step 3
3. Edit or create the file Renviron.site and add the variable MYSQL_HOME which contains the location of your MySQL install. The
file typically isn't created when installing R, so you may need to
create it yourself. You will want to place it under the /etc directory
in your R Home area. If you don't know where that is, you can issue
R.home() at your R prompt. You will be adding a variable named
MYSQL_HOME in variable=value syntax.
Here's an example:
Location of Renviron.site: C:/PROGRA~1/R/R-2.11~1.0/etc/Renviron.site
Content is: MYSQL_HOME=C:/PROGRA~1/MySQL/MYSQLS~1.0/
I had this same issue as well. It took me a while to understand:
that I needed to manually create a text file named Renviron.site in the proper Windows directory, and,
that the manually created Renviron.site file needed to contain the definition of the MYSQL_HOME variable.
Here is my example from Windows 10 and R version 3.2.2:
I issued the command R.home() at the R prompt in R Studio:
R.home()
[1] "C:/PROGRA~1/R/R-32~1.2"
With that information, I navigated to the etc folder in Windows:
C:\Program Files\R\R-3.2.2\etc
I placed a manually created text file called Renviron.site within this directory (the "etc" folder). The only data in the Renviron.site text file is the following:
MYSQL_HOME=C:/PROGRA~1/MySQL/MYSQLS~1.2/
(I wasn't sure whether to use ~1.0 or ~1.2 here based on the output from the R.home() command in R, but, this seemed to work)
Once the file was saved, I restarted R and I was able to install the RMySQL package in R.

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.