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
Related
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
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)
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.
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.
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.