C MySQL API compiler warning problem with redefinition while including header files - mysql

I am compiling a simple c program to test the including of the library files on eclipse cygwin environment mysql-connector-c-6.0.2
The program
#include <my_global.h>
#include <mysql.h>
int main(int argv,char* argc[])
{
printf("my SQL libraries successfully included\n");
return 0;
}
I get the compiler errors as
cygwin warning:
MS-DOS style path detected: C:\MinGW\Workspace\sql_test\Debug
Preferred POSIX equivalent is: /cygdrive/c/MinGW/Workspace/sql_test/Debug
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
In file included from ../sql_test.c:8:
D:\mysql-connector-c-6.0.2\include/my_global.h:1416:1: warning: "floatget" redefined
D:\mysql-connector-c-6.0.2\include/my_global.h:1232:1: warning: this is the location of the previous definition
D:\mysql-connector-c-6.0.2\include/my_global.h:1417:1: warning: "floatstore" redefined
D:\mysql-connector-c-6.0.2\include/my_global.h:1231:1: warning: this is the location of the previous definition
D:\mysql-connector-c-6.0.2\include/my_global.h:1418:1: warning: "doubleget" redefined
D:\mysql-connector-c-6.0.2\include/my_global.h:1220:1: warning: this is the location of the previous definition
D:\mysql-connector-c-6.0.2\include/my_global.h:1419:1: warning: "doublestore" redefined
D:\mysql-connector-c-6.0.2\include/my_global.h:1225:1: warning: this is the location of the previous definition
Finished building: ../sql_test.c
I have verified the my_global.h file and the deceleration of these seems to be valid.
How to turn of these redefinition errors?
Where in eclipse and How do i set this "CYGWIN environment variable option "nodosfilewarning" to turn off this warning".
Here you can see the header file my_global.h of

For the warning, define CYGWIN=nodosfilewarning in the OS environment (control panel -> system -> advanced -> environment variables). If that doesn't work, try logging out to make sure nothing is using the old environment.
For the redefine errors, as Bo says, the compiler is telling you exactly where your mistakes are. If you don't understand them, then you should at least post those lines as part of your question.

Related

Connecting to mysql database with c program

I would like to connect the mysql database using C in CodeBlocks
I downloaded MySQL Connector C 6.1
I added this below to my linker settings
I added this to Compiler in Search directories
I copied libmysql.dll to my project directory and /windows/system
I added #include "mysql.h" to my hello world example and tried to compile it.
#include <stdio.h>
#include <stdlib.h>
#include "mysql.h"
int main()
{
printf("Hello world!\n");
return 0;
}
When I try to compile it I get following errors:
cannot find -l-lmysqlpp
cannot find -l-lmysqlclient
I would be grateful for any help.
EDIT:
Let me upload my test_build_log.html file
-------------- Build: Debug in test (compiler: GNU GCC Compiler)---------------
gcc.exe -o bin\Debug\test.exe obj\Debug\main.o "C:\Program Files\MySQL\MySQL Connector C 6.1\lib\libmysql.lib" "C:\Program Files\MySQL\MySQL Connector C 6.1\lib\vs12\mysqlclient.lib" -l-lmysqlpp -l-lmysqlclient
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -l-lmysqlpp
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -l-lmysqlclient
collect2.exe: error: ld returned 1 exit status
cannot find -l-lmysqlpp
cannot find -l-lmysqlclient
These should be presented to the linker as:
-lmysqlpp
-lmysqlclient
The repeating -l switch indicates something wrong in your linker settings. Make sure there are no entries (including spaces or other hidden characters) in both link library an d Other linker options boxes. You may need to clear and re-enter everything in each box.
One more think to try, view the actual compile command line that is being used:
Code::Blocks can output a build log. Settings->Compiler and debugger->Global compiler settings->{slide tabs to the right}->Build options tab->Save build log to HTML. Turn this feature on, then view the log after your next attempt. There may be something there pointing to the problem.

Failed to build libmysql on windows using vc2008

I want to build libmysql.dll, so I got source code mysql-connector-c-6.1.6-src.zip from http://dev.mysql.com/downloads/connector/c/.
Then cmake-gui.exe to configure and generate vc 2008 sln, leave all settings default.
Then got errors and warnings when building, like this:
mysql-connector-c-6.1.6-src\include\thr_cond.h(109) : error C2065: “ETIMEDOUT”: 未声明的标识符(an unspecified identifier)
mysql-connector-c-6.1.6-src\include\thr_rwlock.h(80) : warning C4013: “TryAcquireSRWLockShared” 未定义(not defined)
mysql-connector-c-6.1.6-src\include\thr_rwlock.h(102) : warning C4013: “TryAcquireSRWLockExclusive” 未定义(not defined)
I searched the source, and find ETIMEDOUT is defined in my_pthread.h, so I include this header in thr_cond.h, but still error.
And TryAcquireSRWLockShared and TryAcquireSRWLockExclusive seem only supported on Win7 and later !
Do I have done something wrong?
How can I build libmysql?
Any help will be appreciated.
Download the previous version (6.0.2), it doesn's use the TryAcquireSRWLockShared() API function.
With a few minor tweeks, it compiles clean with MSVC 2008.
Here are the modifications (based on the extracted zip file root):
Replace line 306 of include/config-win.h with:
// avoid annoying warning
#ifndef HAVE_COMPRESS
# define HAVE_COMPRESS
#endif
Comment lines 350-367 of CMakeLists.txt (CPack instructions cause CMake to fail)
Follow instructions in BUILD.win

Connecting MYSQL using C program in Eclipse

I am connecting the Mysql using c program in eclipse, I am using CYGWIN compiler to compile program. I have installed the mysql c connector and added the include files to the compiler and linker
but i am getting error
**** Build of configuration Debug for project DbConnectionC ****
make all
Building file: ../connection.c
Invoking: Cygwin C Compiler
gcc -I"C:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\include" -include"C:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\include\mysql.h" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"connection.d" -MT"connection.d" -o "connection.o" "../connection.c"
cygwin warning:
MS-DOS style path detected: D:\java\workspace\DbConnectionC\Debug
Preferred POSIX equivalent is: /cygdrive/d/java/workspace/DbConnectionC/Debug
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
../connection.c: In function `main':
../connection.c:57: warning: char format, different type arg (arg 2)
../connection.c:57: warning: char format, different type arg (arg 2)
../connection.c:61: warning: char format, different type arg (arg 2)
../connection.c:61: warning: char format, different type arg (arg 2)
Finished building: ../connection.c
Building target: DbConnectionC.exe
Invoking: Cygwin C Linker
gcc -L"C:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\lib\opt" -o "DbConnectionC.exe" ./connection.o -llibmysql.lib -lmysqlclient.lib
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/ld: cannot find -llibmysql.lib
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/ld: cannot find -lmysqlclient.lib
collect2: ld returned 1 exit status
make: *** [DbConnectionC.exe] Error 1
makefile:29: recipe for target `DbConnectionC.exe' failed
**** Build Finished ****
Please help me on this
thanks in advance
In the first part you have some warnings about possible problems:
../connection.c:39: warning: implicit declaration of function `exit'
This means function exit() is not declared, your source needs an #include <stdlib.h>
../connection.c:46: warning: control reaches end of non-void function
You don't return a value at the end of main(), add a return 0; if the program succeeds.
In the second part are linker warnings:
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/ld: cannot find -llibmysql.lib
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/ld: cannot find -lmysqlclient.lib
which means the linker needs a path to the libraries or the libraries do not exist or the library names are misspelled.
One possible solution is using -lmysql -lmysqlclient instead of -llibmysql.lib -lmysqlclient.lib, but I'm not that familiar with Windows.
Having said that, I suggest strongly, you look at https://stackoverflow.com/tags/c/info and look at some book links.

Setting up Mysql++ in linux

I want to connect to a mysql database with C++ in linux. On my local machine I am running Ubuntu, and installed the mysql server and client packages:
sudo apt-get install mysql-server mysql-client
I came across Mysql++ but have some problems when running ./configure from their binary package. The error says:
checking for MySQL library directory... configure: error: Didn't find mysqlclient library in '/usr/lib64 /usr/lib /usr/lib64/mysql /usr/lib/mysql /usr/local/lib64 /usr/local/lib /usr/local/lib/mysql /usr/local/mysql/lib /usr/local/mysql/lib/mysql /usr/mysql/lib/mysql /opt/mysql/lib /opt/mysql/lib/mysql /sw/lib /sw/lib/mysql'
I see where I can use this command to specify the path:
./configure --with-mysql-lib=/...
but I do not know where to point it to. I used whereis mysql but cannot find any mysql directory that contains a lib subdirectory. Where would the mysqlclient libraries be installed?
EDIT:
After doing locate libmysqlclient I got back
/usr/lib/i386-linux-gnu/libmysqlclient.so.18
/usr/lib/i386-linux-gnu/libmysqlclient.so.18.0.0
/usr/lib/i386-linux-gnu/libmysqlclient_r.so.18
/usr/lib/i386-linux-gnu/libmysqlclient_r.so.18.0.0
/usr/share/doc/libmysqlclient18
/usr/share/doc/libmysqlclient18/changelog.Debian.gz
/usr/share/doc/libmysqlclient18/copyright
/var/cache/apt/archives/libmysqlclient18_5.5.22-0ubuntu1_i386.deb
/var/lib/dpkg/info/libmysqlclient18:i386.list
/var/lib/dpkg/info/libmysqlclient18:i386.md5sums
/var/lib/dpkg/info/libmysqlclient18:i386.postinst
/var/lib/dpkg/info/libmysqlclient18:i386.postrm
/var/lib/dpkg/info/libmysqlclient18:i386.shlibs
So, I tried ./configure --with-mysql-lib=/usr/lib/i386-linux-gnu and it seems to complete without any complaining.
Although this solves the problem of getting ./configure to complete, I still have further troubles. When I run make things go fine until this point:
In file included from ./lib/sql_buffer.h:31:0,
from ./lib/sql_buffer.cpp:26: ./lib/refcounted.h:258:2: error: ‘size_t’ does not name a type
./lib/refcounted.h: In constructor ‘mysqlpp::RefCountedPointer::RefCountedPointer()’: ./lib/refcounted.h:89:2: error:
class ‘mysqlpp::RefCountedPointer’ does not have any
field named ‘refs_’ ./lib/refcounted.h: In constructor
‘mysqlpp::RefCountedPointer::RefCountedPointer(T*)’:
./lib/refcounted.h:100:2: error: class ‘mysqlpp::RefCountedPointer’ does not have any field named ‘refs_’
./lib/refcounted.h:104:4: error: ‘refs_’ was not declared in this
scope ./lib/refcounted.h:104:16: error: expected type-specifier before
‘size_t’ ./lib/refcounted.h:104:16: error: expected ‘;’ before
‘size_t’ ./lib/refcounted.h: In constructor
‘mysqlpp::RefCountedPointer::RefCountedPointer(const
ThisType&)’: ./lib/refcounted.h:112:2: error: class
‘mysqlpp::RefCountedPointer’ does not have any field
named ‘refs_’ ./lib/refcounted.h:115:8: error: ‘refs_’ was not
declared in this scope ./lib/refcounted.h: In destructor
‘mysqlpp::RefCountedPointer::~RefCountedPointer()’:
./lib/refcounted.h:125:7: error: ‘refs_’ was not declared in this
scope ./lib/refcounted.h: In member function ‘void
mysqlpp::RefCountedPointer::swap(mysqlpp::RefCountedPointer::ThisType&)’: ./lib/refcounted.h:246:13: error: ‘refs_’ was
not declared in this scope make: *** [mysqlpp_sql_buffer.o] Error 1
I'm not really familiar with C++, so I'm not sure what the error means exactly. Any help or direction on how to get Mysql++ setup from this point would be much appreciated. Although, I admit that I'm also starting to look for alternative libraries to use.
this problem is caused because size_t depends on the inclusion of stddef namespace before it is called in the configuration (make) files.
i had the very same problem (using an amazon EC2 ubuntu 12.04 cloud server) and solved it by editing the offending file (sql_buffer.cpp located, in my case, /home/ubuntu/mysql++-3.1.0/lib) and including stddef (while also moving string namespace up):
#include <stddef.h>
#include <string.h>
#include "sql_buffer.h"
your question is answered with this correction. BUT, you might have additional problems, like i did. so i explain how i solved some subsequent problems, which you might or might not have also.
you might have to use
sudo chown username sql_buffer.cpp
to be able to edit the file, depending on how your install is setup (i am user ubuntu, for example).
i then bumped into another problem:
./ssx/genv2.cpp: In function âbool generate_ssqls2(const char*, const ParseV2*)â:
./ssx/genv2.cpp:70:28: error: âstrcmpâ was not declared in this scope
so i edited the offending file (genv2.cpp) and included string namespace
#include <string.h>
then i had ANOTHER problem with:
./libmysqlpp_ssqls2parse.a(ssqls2parse_parsev2.o): In function `Type':
/home/ubuntu/mysql++-3.1.0/./ssx/parsev2.cpp:256: undefined reference to `mysqlpp::internal::str_to_lwr
i could have edited Makefile.in but chose to simply run in command line:
sudo g++ -o test_ssqls2 test_ssqls2_ssqls2.o -lmysqlpp_ssqls2parse -L. -lmysqlclient -L/usr/lib/x86_64-linux-gnu -lmysqlpp
i then continued the make process.
that worked for me: mysql++ installed and running.
You need to install the header (dev) files, I assume one of these:
apt-cache search mysql
...
libmysqlclient-dev - MySQL database development files
libmysqlclient16 - MySQL database client library
libmysql++-dev - MySQL C++ library bindings (development)
libmysqlcppconn-dev - MySQL Connector for C++ (development files)
...
--with-mysql-lib should not be necessary because the files will be installed in the default locations.

Problem with MySQL driver for unixODBC on Debian Lenny

On OpenSuse 11.2, I successfully compiled, linked, and ran the following code which installs a data source for a MySQL database with unixODBC:
#include <iostream>
#include <sql.h>
#include <sqlext.h>
#include <odbcinst.h>
/* Add a data source for the following MySQL db: db=testdb, username=test, password = test. */
void inst()
{
BOOL ret = SQLConfigDataSource(NULL, ODBC_ADD_DSN, "MySQL driver",
"DSN=mysource\0UID=test\0PWD=test\0DATABASE=testdb\0\0");
if (!ret) {
DWORD errCode;
char errBuf[SQL_MAX_MESSAGE_LENGTH];
WORD msgLen;
SQLInstallerError(1, &errCode, errBuf, SQL_MAX_MESSAGE_LENGTH, &msgLen);
std::cerr << errBuf << std::endl;
}
}
int main()
{
inst();
return 0;
}
With the same code on Debian Lenny, I have had problems. First, I compiled this code the following way:
c++ -o main main.cc -lodbc -lodbcinst -L/usr/lib/odbc -lmyodbc
It went ok. But when I attempted to run the resulting binary, I got a linker error which in fact was confirmed by typing ldd main:
libmyodbc3_r-3.51.15.so => not found
Although I correctly installed unixODBC and the associated MySQL driver (myodbc) on my host (Debian Lenny) the simplest way (i.e. via aptitude), I could not find this shared library.
I wrongly thought, well, I will create a symlink on /usr/lib/odbc/libmyodbc.so. Anyway now my program returns the following message:
General installer error
So I feel the file libmyodbc3_r-3.51.15.so is really missing.
Note: on Debian Lenny, the version of unixODBC is 2.2.11, and the version of MySQL is 5.0.51a
Anyone ever ran into such a situation ? Any help would be appreciated.
The option
-L/usr/lib/odbc
tells the compiler where to find the library for linking.
But the system doesn't know where to find the library when you run the executable.
You need to either statically link against libmyodbc, or tell the system where to find the library.
The first can be done by changing
-lmyodbc
to
-static -lmyodbc
The second can be done by editing /etc/ld.so.conf (or adding to /etc/ld.so.conf.d) and re-running ldconfig or by setting the LD_LIBRARY_PATH environment variable to include /usr/lib/odbc