Can not compile simple mysql program - mysql

cblog.c:
#include "html.h"
#include "config.h"
#include <mysql/mysql.h>
//#include <my_global.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
conn = mysql_init(NULL);
// Connect to database
if (!msyql_real_connect(conn, server, username, password, database, 0, NULL, 0)) {
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}
// Query the DB
if (mysql_query(conn, "show tables")) {
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}
res = mysql_use_result(conn);
htmlf("MySQL Tables in mysql database:\n");
while ((row = mysql_fetch_row(res)) != NULL)
htmlf("%s \n", row[0]);
mysql_free_result(res);
mysql_close(conn);
html("Hello World!");
return 0;
}
Makefile:
all:
# gcc -Wall cblog.c html.c -o cblog `mysql_config --cflags --libs`
# gcc -Wall cblog.c html.c -L/usr/lib -lmysqlclient -o cblog
gcc cblog.c html.c -Wall $(shell mysql_config --cflags) -o cblog $(shell mysql_config --libs)
test: all
./cblog
Output:
ttouch cblog$ make
gcc cblog.c html.c -g -Wall -I/usr/include/mysql -fPIC -pipe -fstack-protector --param=ssp-buffer-size=4 -fno-strict-aliasing -DBIG_JOINS=1 -fomit-frame-pointer -g -DNDEBUG -o cblog -L/usr/lib -lmysqlclient -lpthread -lz -lm -lssl -lcrypto -ldl
cblog.c: In function ‘main’:
cblog.c:16:2: warning: implicit declaration of function ‘msyql_real_connect’ [-Wimplicit-function-declaration]
if (!msyql_real_connect(conn, server, username, password, database, 0, NULL, 0)) {
^
/tmp/ccs1WQsi.o: In function `main':
/media/files/Lab/cblog/cblog.c:16: undefined reference to `msyql_real_connect'
collect2: error: ld returned 1 exit status
make: *** [all] Error 1
I know this question has been answered over a thousand times, I've searched all over the internet, I've tested putting mysql_config at the beginning or at the end. I know that it gives the right paths (checked)
ls /usr/lib/ | grep mysql:
libmysqlclient.a
libmysqlclient_r.a
libmysqlclient_r.so
libmysqlclient_r.so.18
libmysqlclient_r.so.18.0.0
libmysqlclient.so
libmysqlclient.so.18
libmysqlclient.so.18.0.0
libmysqld.a
libmysqld.so
libmysqld.so.18
libmysqlservices.a
mysql
tdbcmysql1.0.0
ls /usr/include/mysql | grep mysql:
mysql_com.h
mysqld_ername.h
mysqld_error.h
mysql_embed.h
mysql.h
mysql_time.h
mysql_version.h
Sorry for the noobish question, but I've been banging my head for about 4-5 hours

You have a typo in the function name, msyql_real_connect should be mysql_real_connect

Related

mysql.h compile, but not its functions

I am trying to see how to embed sql code in a C program, but I have an issue I am not able to understand when I compile this code :
#include <stdio.h>
#include <stdlib.h>
#include <mysql/mysql.h>
MYSQL *mysql;
MYSQL_RES *results;
MYSQL_ROW record;
int main() {
mysql = mysql_init(NULL);
if (mysql == NULL) {
fprintf(stderr, "%s\n", mysql_error(mysql));
return 1;
}
if (mysql_real_connect(mysql, "localhost", "root", "PassWord",
NULL, 0, NULL, 0) == NULL) {
fprintf(stderr, "%s\n", mysql_error(mysql));
mysql_close(mysql);
return 1;
}
mysql_query(mysql, "SHOW DATABASES");
return 0;
}
this is what the compiler tell me when I compile it :
clang++ -g -c testSql.cc
clang++ testSql.o -o testSql
/usr/bin/ld: testSql.o: in function `main':
/home/antoine/Documenti/L3/Information Management II/code/testSql.cc:12: undefined reference to `mysql_init'
/usr/bin/ld: /home/antoine/Documenti/L3/Information Management II/code/testSql.cc:15: undefined reference to `mysql_error'
/usr/bin/ld: /home/antoine/Documenti/L3/Information Management II/code/testSql.cc:19: undefined reference to `mysql_real_connect'
/usr/bin/ld: /home/antoine/Documenti/L3/Information Management II/code/testSql.cc:21: undefined reference to `mysql_error'
/usr/bin/ld: /home/antoine/Documenti/L3/Information Management II/code/testSql.cc:22: undefined reference to `mysql_close'
/usr/bin/ld: /home/antoine/Documenti/L3/Information Management II/code/testSql.cc:26: undefined reference to `mysql_query'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:25: testSql] Errore 1
I have check in the mysql.h file, those function are implemented, so I do not understand why I have this "undifined reference" error, do any onehave an idea on the origin of this error ?
Thank you all for the answer. I had to provide a linker in my compilation.
I am now compiling with
clang++ -g -c testSql.cc
clang++ testSql.o -o testSql `mysql_config --cflags --libs`
instead of
clang++ -g -c testSql.cc
clang++ testSql.o -o testSql
and it compile correctly.
Thank you !

Unable to install mysql gem after MacOS 10.14 install and brew update

after macOS 10.14 install + Brew update my dev system is broken.
I am unable to install the mysql gem. When trying to install I get:
$ gem install mysql -v '2.8.1' --source 'http://rubygems.org/'
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
current directory: /Users/MYACCOUNT/.rvm/gems/ruby-1.8.7-p374#WEBPROJECT/gems/mysql-2.8.1/ext/mysql_api
/Users/MYACCOUNT/.rvm/rubies/ruby-1.8.7-p374/bin/ruby -r ./siteconf20180926-49343-waujia-0.rb extconf.rb
checking for mysql_ssl_set()... yes
checking for rb_str_set_len()... yes
checking for rb_thread_start_timer()... yes
checking for mysql.h... no
checking for mysql/mysql.h... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/MYACCOUNT/.rvm/rubies/ruby-1.8.7-p374/bin/ruby
--with-mysql-config
--without-mysql-config
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Users/MYACCOUNT/.rvm/gems/ruby-1.8.7-p374#WEBPROJECT/extensions/x86-darwin-14/1.8/mysql-2.8.1/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /Users/MYACCOUNT/.rvm/gems/ruby-1.8.7-p374#WEBPROJECT/gems/mysql-2.8.1 for inspection.
Results logged to /Users/MYACCOUNT/.rvm/gems/ruby-1.8.7-p374#WEBPROJECT/extensions/x86-darwin-14/1.8/mysql-2.8.1/gem_make.out
the relative mkmf.log is:
have_func: checking for mysql_ssl_set()... -------------------- yes
"/usr/local/bin/gcc-4.9 -o conftest -I. -I/Users/MYACCOUNT/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/1.8/i686-darwin14.4.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I/usr/local/Cellar/mysql/5.7.21/include/mysql -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl098/include -O2 -fno-tree-dce -fno-optimize-sibling-calls -fno-common -pipe -fno-common conftest.c -L. -L/Users/MYACCOUNT/.rvm/rubies/ruby-1.8.7-p374/lib -L. -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl098/lib -L/usr/local/Cellar/mysql/5.7.21/lib -lmysqlclient -lssl -lcrypto -lruby-static -L/usr/local/Cellar/mysql/5.7.21/lib -lmysqlclient -lssl -lcrypto -ldl -lobjc "
conftest.c: In function 't':
conftest.c:3:53: error: 'mysql_ssl_set' undeclared (first use in this function)
int t() { void ((*volatile p)()); p = (void ((*)()))mysql_ssl_set; return 0; }
^
conftest.c:3:53: note: each undeclared identifier is reported only once for each function it appears in
checked program was:
/* begin */
1: /*top*/
2: int main() { return 0; }
3: int t() { void ((*volatile p)()); p = (void ((*)()))mysql_ssl_set; return 0; }
/* end */
"/usr/local/bin/gcc-4.9 -o conftest -I. -I/Users/MYACCOUNT/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/1.8/i686-darwin14.4.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I/usr/local/Cellar/mysql/5.7.21/include/mysql -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl098/include -O2 -fno-tree-dce -fno-optimize-sibling-calls -fno-common -pipe -fno-common conftest.c -L. -L/Users/MYACCOUNT/.rvm/rubies/ruby-1.8.7-p374/lib -L. -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl098/lib -L/usr/local/Cellar/mysql/5.7.21/lib -lmysqlclient -lssl -lcrypto -lruby-static -L/usr/local/Cellar/mysql/5.7.21/lib -lmysqlclient -lssl -lcrypto -ldl -lobjc "
ld: warning: directory not found for option '-L/usr/local/opt/openssl098/lib'
checked program was:
/* begin */
1: /*top*/
2: int main() { return 0; }
3: int t() { mysql_ssl_set(); return 0; }
/* end */
--------------------
have_func: checking for rb_str_set_len()... -------------------- yes
"/usr/local/bin/gcc-4.9 -o conftest -I. -I/Users/MYACCOUNT/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/1.8/i686-darwin14.4.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I/usr/local/Cellar/mysql/5.7.21/include/mysql -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl098/include -O2 -fno-tree-dce -fno-optimize-sibling-calls -fno-common -pipe -fno-common conftest.c -L. -L/Users/MYACCOUNT/.rvm/rubies/ruby-1.8.7-p374/lib -L. -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl098/lib -L/usr/local/Cellar/mysql/5.7.21/lib -lmysqlclient -lssl -lcrypto -lruby-static -L/usr/local/Cellar/mysql/5.7.21/lib -lmysqlclient -lssl -lcrypto -ldl -lobjc "
conftest.c: In function 't':
conftest.c:3:53: error: 'rb_str_set_len' undeclared (first use in this function)
int t() { void ((*volatile p)()); p = (void ((*)()))rb_str_set_len; return 0; }
^
conftest.c:3:53: note: each undeclared identifier is reported only once for each function it appears in
checked program was:
/* begin */
1: /*top*/
2: int main() { return 0; }
3: int t() { void ((*volatile p)()); p = (void ((*)()))rb_str_set_len; return 0; }
/* end */
"/usr/local/bin/gcc-4.9 -o conftest -I. -I/Users/MYACCOUNT/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/1.8/i686-darwin14.4.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I/usr/local/Cellar/mysql/5.7.21/include/mysql -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl098/include -O2 -fno-tree-dce -fno-optimize-sibling-calls -fno-common -pipe -fno-common conftest.c -L. -L/Users/MYACCOUNT/.rvm/rubies/ruby-1.8.7-p374/lib -L. -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl098/lib -L/usr/local/Cellar/mysql/5.7.21/lib -lmysqlclient -lssl -lcrypto -lruby-static -L/usr/local/Cellar/mysql/5.7.21/lib -lmysqlclient -lssl -lcrypto -ldl -lobjc "
ld: warning: directory not found for option '-L/usr/local/opt/openssl098/lib'
checked program was:
/* begin */
1: /*top*/
2: int main() { return 0; }
3: int t() { rb_str_set_len(); return 0; }
/* end */
--------------------
have_func: checking for rb_thread_start_timer()... -------------------- yes
"/usr/local/bin/gcc-4.9 -o conftest -I. -I/Users/MYACCOUNT/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/1.8/i686-darwin14.4.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I/usr/local/Cellar/mysql/5.7.21/include/mysql -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl098/include -O2 -fno-tree-dce -fno-optimize-sibling-calls -fno-common -pipe -fno-common conftest.c -L. -L/Users/MYACCOUNT/.rvm/rubies/ruby-1.8.7-p374/lib -L. -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl098/lib -L/usr/local/Cellar/mysql/5.7.21/lib -lmysqlclient -lssl -lcrypto -lruby-static -L/usr/local/Cellar/mysql/5.7.21/lib -lmysqlclient -lssl -lcrypto -ldl -lobjc "
conftest.c: In function 't':
conftest.c:3:53: error: 'rb_thread_start_timer' undeclared (first use in this function)
int t() { void ((*volatile p)()); p = (void ((*)()))rb_thread_start_timer; return 0; }
^
conftest.c:3:53: note: each undeclared identifier is reported only once for each function it appears in
checked program was:
/* begin */
1: /*top*/
2: int main() { return 0; }
3: int t() { void ((*volatile p)()); p = (void ((*)()))rb_thread_start_timer; return 0; }
/* end */
"/usr/local/bin/gcc-4.9 -o conftest -I. -I/Users/MYACCOUNT/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/1.8/i686-darwin14.4.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I/usr/local/Cellar/mysql/5.7.21/include/mysql -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl098/include -O2 -fno-tree-dce -fno-optimize-sibling-calls -fno-common -pipe -fno-common conftest.c -L. -L/Users/MYACCOUNT/.rvm/rubies/ruby-1.8.7-p374/lib -L. -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl098/lib -L/usr/local/Cellar/mysql/5.7.21/lib -lmysqlclient -lssl -lcrypto -lruby-static -L/usr/local/Cellar/mysql/5.7.21/lib -lmysqlclient -lssl -lcrypto -ldl -lobjc "
ld: warning: directory not found for option '-L/usr/local/opt/openssl098/lib'
checked program was:
/* begin */
1: /*top*/
2: int main() { return 0; }
3: int t() { rb_thread_start_timer(); return 0; }
/* end */
--------------------
have_header: checking for mysql.h... -------------------- no
"/usr/local/bin/gcc-4.9 -E -I. -I/Users/MYACCOUNT/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/1.8/i686-darwin14.4.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I/usr/local/Cellar/mysql/5.7.21/include/mysql -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl098/include -O2 -fno-tree-dce -fno-optimize-sibling-calls -fno-common -pipe -fno-common conftest.c -o conftest.i"
In file included from conftest.c:1:0:
/usr/local/Cellar/mysql/5.7.21/include/mysql/mysql.h:35:23: fatal error: sys/types.h: No such file or directory
#include <sys/types.h>
^
compilation terminated.
checked program was:
/* begin */
1: #include <mysql.h>
/* end */
--------------------
have_header: checking for mysql/mysql.h... -------------------- no
"/usr/local/bin/gcc-4.9 -E -I. -I/Users/MYACCOUNT/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/1.8/i686-darwin14.4.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I/usr/local/Cellar/mysql/5.7.21/include/mysql -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl098/include -O2 -fno-tree-dce -fno-optimize-sibling-calls -fno-common -pipe -fno-common conftest.c -o conftest.i"
In file included from conftest.c:1:0:
/usr/local/include/mysql/mysql.h:35:23: fatal error: sys/types.h: No such file or directory
#include <sys/types.h>
^
compilation terminated.
checked program was:
/* begin */
1: #include <mysql/mysql.h>
/* end */
--------------------
I have mysql installed via Brew and keep mysql, mysql#5.6 or mysql#5.7 active. Path is set in .bash_profile:
### Customize path for MYSQL
MYSQL=/usr/local/mysql/bin
export PATH=$PATH:$MYSQL
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
When I switch to mysql#5.6 or 5.7 I change the path accordingly.
There appears to be some problem with mysql in general.
While one webapp in Ruby 1.8.7, Rails 3.2.5 with mysql database is running, two other webapps with the same technology stack are unable to either reinstall the mysql gem or connect to the database.
$ rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
Mysql::Error: Table 'dev_WEBPROJECT.safts' doesn't exist: SHOW FULL FIELDS FROM `safts`
/Users/MYACCOUNT/.rvm/gems/ruby-1.8.7-p374#WEBPROJECT/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in `query'
/Users/MYACCOUNT/.rvm/gems/ruby-1.8.7-p374#WEBPROJECT/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in `execute'
/Users/MYACCOUNT/.rvm/gems/ruby-1.8.7-p374#WEBPROJECT/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `log'
.
.
.
/Users/MYACCOUNT/.rvm/gems/ruby-1.8.7-p374#WEBPROJECT/gems/rake-0.9.6/lib/rake/application.rb:70:in `run'
/Users/MYACCOUNT/.rvm/gems/ruby-1.8.7-p374#WEBPROJECT/gems/rake-0.9.6/bin/rake:37
/Users/MYACCOUNT/.rvm/gems/ruby-1.8.7-p374#WEBPROJECT/bin/rake:22:in `load'
/Users/MYACCOUNT/.rvm/gems/ruby-1.8.7-p374#WEBPROJECT/bin/rake:22
/Users/MYACCOUNT/.rvm/gems/ruby-1.8.7-p374#WEBPROJECT/bin/ruby_executable_hooks:15
Tasks: TOP => db:migrate => environment
Can anyone help?
Mojave changed the location of header files necessary for compiling C extensions. You might need to run the following command to install mysql gem:
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
Ref: https://gorails.com/setup/osx/10.14-mojave
Do you have xcode installed? /usr/bin/xcodebuild -version

Cuda compiling error when coming to g++ compiling step

nvcc -D_DEBUG --use_fast_math -I"/usr/local/cuda-9.0//include" -I"/usr/include/eigen3" -I"/home/xingfu/NVIDIA_CUDA-9.0_Samples/common/inc" -dlink --machine 64 -arch=sm_50 -c -o kernel_cuda.o ../CudaTest/kernel.cu
g++ -c -pipe -g -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_CORE_LIB -I../CudaTest -I. -I/usr/local/cuda-9.0/include -isystem /usr/include/eigen3 -I../NVIDIA_CUDA-9.0_Samples/common/inc -isystem /usr/local/include -I../Qt5.11.0/5.11.0/gcc_64/include -I../Qt5.11.0/5.11.0/gcc_64/include/QtCore -I. -I../Qt5.11.0/5.11.0/gcc_64/mkspecs/linux-g++ -o LBDM.o ../CudaTest/LBDM.cpp
The two steps above have passed, however, when run the following step, the error occured:
g++ -Wl,-rpath,/home/xingfu/Qt5.11.0/5.11.0/gcc_64/lib -o CudaTest kernel_cuda.o LBDM.o -L/usr/local/cuda-9.0//lib64/ -lcuda -lcudart -lcublas -L/home/xingfu/CudaTest/../../../usr/local/lib/ -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -L/home/xingfu/Qt5.11.0/5.11.0/gcc_64/lib -lQt5Core -lpthread
The compiler error shows:
kernel_cuda.o: In function `__sti____cudaRegisterAll()':
tmpxft_00000e7d_00000000-5_kernel.cudafe1.cpp:(.text+0x177e): undefined reference to `__cudaRegisterLinkedBinary_41_tmpxft_00000e7d_00000000_6_kernel_cpp1_ii_channel'
How can I fix the error?
What's more,
I add the -dlink, because it shows the error when dealing the following step:
nvcc -D_DEBUG --use_fast_math -I"/usr/local/cuda-9.0//include" -I"/usr/include/eigen3" -I"/home/xingfu/NVIDIA_CUDA-9.0_Samples/common/inc" --machine 64 -arch=sm_50 -c -o kernel_cuda.o ../CudaTest/kernel.cu
and the error is:
ptxas fatal : Unresolved extern function 'cublasCreate_v2'
However, when I add -dlink, the error occured like I said above.
BTW, before I add -dlink, I can run a simple function in another test project like this:
__global__ void add(float* x, float * y, float* z, int n)
{
int index = threadIdx.x + blockIdx.x * blockDim.x;
int stride = blockDim.x * gridDim.x;
for (int i = index; i < n; i += stride)
{
z[i] = x[i] + y[i];
}
}
After I add -dlink, the test project shows an error:
cuda_code_cuda.o: In function `__sti____cudaRegisterAll()':
tmpxft_000017db_00000000-5_cuda_code.cudafe1.cpp:(.text+0x861): undefined reference to `__cudaRegisterLinkedBinary_44_tmpxft_000017db_00000000_6_cuda_code_cpp1_ii_5b538d80'
which is very similar to the above error.
For relocatable device code linking, which seems to be what you're after, the recommended sequence would be as follows. In addition, it appears your code is attempting to use the cublas device interface, so for good measure we'll add those libraries to the link steps:
#replace -dlink -c with -dc
nvcc -D_DEBUG --use_fast_math -I"/usr/local/cuda-9.0//include" -I"/usr/include/eigen3" -I"/home/xingfu/NVIDIA_CUDA-9.0_Samples/common/inc" -dc --machine 64 -arch=sm_50 -o kernel_cuda.o ../CudaTest/kernel.cu
#generate device-linked object with cublas device libraries
nvcc -D_DEBUG --use_fast_math -dlink --machine 64 -arch=sm_50 -o kernel_dlink.o kernel_cuda.o -lcublas -lcublas_device -lcudadevrt
#no change to this line
g++ -c -pipe -g -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_CORE_LIB -I../CudaTest -I. -I/usr/local/cuda-9.0/include -isystem /usr/include/eigen3 -I../NVIDIA_CUDA-9.0_Samples/common/inc -isystem /usr/local/include -I../Qt5.11.0/5.11.0/gcc_64/include -I../Qt5.11.0/5.11.0/gcc_64/include/QtCore -I. -I../Qt5.11.0/5.11.0/gcc_64/mkspecs/linux-g++ -o LBDM.o ../CudaTest/LBDM.cpp
#add device-linked object to final link phase plus cublas device libraries
g++ -Wl,-rpath,/home/xingfu/Qt5.11.0/5.11.0/gcc_64/lib -o CudaTest kernel_cuda.o LBDM.o kernel_dlink.o -L/usr/local/cuda-9.0//lib64/ -lcuda -lcudart -lcublas -lcublas_device -lcudadevrt -L/home/xingfu/CudaTest/../../../usr/local/lib/ -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -L/home/xingfu/Qt5.11.0/5.11.0/gcc_64/lib -lQt5Core -lpthread

Can not link libmysqlclient.a?

I'm using Ubuntu 14.04, and I installed libmysqlclient-dev package already. But I always get link error because mysql_init symbol missing.
My source code, Makefile, run-time result and symbol info are as follows:
igsrd#naivechou/~/project/m01/uuid_sign>cat main.cpp
#include <cstdio>
#include <cstdlib>
#include "mysql/mysql.h"
int main(int argc,char** argv)
{
auto con = mysql_init(nullptr);
//printf("mysql client version : %s\n",mysql_get_client_info());
exit(EXIT_SUCCESS);
}
igsrd#naivechou/~/project/m01/uuid_sign>LANG= && make -B
g++ -o main.o -c main.cpp -std=c++11 -ggdb
g++ -o uuid_sign -L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -ldl main.o
main.o: In function `main':
/home/igsrd/project/m01/uuid_sign/main.cpp:6: undefined reference to `mysql_init'
collect2: error: ld returned 1 exit status
make: *** [uuid_sign] Error 1
igsrd#naivechou/~/project/m01/uuid_sign>nm -C /usr/lib/x86_64-linux-gnu/libmysqlclient.a | grep mysql_init
0000000000002b10 T mysql_init
0000000000002d30 T mysql_init_character_set
U mysql_init_character_set
Source is very simple, just one line to call mysql_init().
Making process shows every options for compiler and linker, I think there are no missing options.
Error message is undefined reference of linking error, so I dump libmysqlclient.a to grep the mysql_init, and it is not on undefined state.
Now I really have no idea. What's wrong with this ?
Change your second command, try this (change the position of main.o):
g++ -o uuid_sign main.o -L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -ldl

Using mysql in c programming

I installed ubuntu on a virtual machine. There, I installed mysql server sudo apt-get install mysql-server .This worked, because I could acces mysql-u root -p password
After that, I did : sudo apt-get install libmysqlclient-dev
#include <my_global.h>
#include <mysql.h>
int main(int argc, char **argv)
{
printf("MySQL client version: %s\n", mysql_get_client_info());
exit(0);
}
When I compile this with
gcc version.c -o version `mysql_config --cflags --libs`
it works.
But when I compile this one from below
gcc createdb.c -o createdb -std=c99 `mysql_config --cflags --libs`
I get some errors.
#include <my_global.h>
#include <mysql.h>
int main(int argc, char **argv)
{
MYSQL *con = mysql_init(NULL);
if (con == NULL)
{
fprintf(stderr, "%s\n", mysql_error(con));
exit(1);
}
if (mysql_real_connect(con, "localhost", "root", "root_pswd",
NULL, 0, NULL, 0) == NULL)
{
fprintf(stderr, "%s\n", mysql_error(con));
mysql_close(con);
exit(1);
}
if (mysql_query(con, "CREATE DATABASE testdb"))
{
fprintf(stderr, "%s\n", mysql_error(con));
mysql_close(con);
exit(1);
}
mysql_close(con);
exit(0);
}
Errors:
"Usage:: No such file or directory
[OPTIONS]: No such file or directory
Options:: No such file or directory
[-I/usr/include/mysql: No such file or directory
[-L/user/lib/x86_64-linux-gnu: No such file or directory
.
.
.
unrecognized command line option '--cflags'
unrecognized command line option '--libs'
.
.
unrecognized command line option '--socket'
unrecognized command line option '--port' "
Can someone explain me what I did wrong,and how to fix it?
I just want to get some data from tables in a C program.
I suspect you actually ran
gcc createdb.c -o createdb -std=c99 `mysql_config` --cflags --libs
rather than
gcc createdb.c -o createdb -std=c99 `mysql_config --cflags --libs`
That’s not going to work; mysql_config, if it doesn’t get any arguments, is going to print out a bunch of usage instructions, which will be passed to gcc, and then you’ll follow that with --cflags --libs, which gcc also doesn’t understand. gcc is severely confused and complains.
If you make sure those arguments get to mysql_config rather than gcc, everyone will be happy.