Below is my small piece of code :
#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);
}
As evident, the only objective is to get this small program up and running, so nothing much to boast about.But to my dismay it became a headache for me. First I got an error which I posted as this SO question which I fortunately resolved. Now I am getting a stream of errors as
described below :
-------------- Build: Debug in mysqlconntest (compiler: GNU GCC Compiler)---------------
gcc.exe -Wall -fexceptions -g -I"C:\Program Files (x86)\MySQL\MySQL Server 5.7\include" -I"C:\Program Files (x86)\MySQL\MySQL Server 5.7\include" -c C:\Users\Sajith\Documents\CodeBlocks\mysqlconntest\main.cpp -o obj\Debug\main.o
In file included from C:\Users\Sajith\Documents\CodeBlocks\mysqlconntest\main.cpp:2:0:
C:\Program Files (x86)\MySQL\MySQL Server 5.7\include/my_global.h:211:19: error: conflicting declaration 'typedef int mode_t'
In file included from c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.7.1/../../../../include/io.h:20:0,
from C:\Program Files (x86)\MySQL\MySQL Server 5.7\include/my_global.h:32,
from C:\Users\Sajith\Documents\CodeBlocks\mysqlconntest\main.cpp:2:
c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.7.1/../../../../include/sys/types.h:99:17: error: 'mode_t' has a previous declaration as 'typedef _mode_t mode_t'
In file included from C:\Users\Sajith\Documents\CodeBlocks\mysqlconntest\main.cpp:2:0:
C:\Program Files (x86)\MySQL\MySQL Server 5.7\include/my_global.h:212:19: error: conflicting declaration 'typedef SSIZE_T ssize_t'
In file included from c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.7.1/../../../../include/io.h:20:0,
from C:\Program Files (x86)\MySQL\MySQL Server 5.7\include/my_global.h:32,
from C:\Users\Sajith\Documents\CodeBlocks\mysqlconntest\main.cpp:2:
c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.7.1/../../../../include/sys/types.h:118:18: error: 'ssize_t' has a previous declaration as 'typedef _ssize_t ssize_t'
In file included from C:\Users\Sajith\Documents\CodeBlocks\mysqlconntest\main.cpp:2:0:
C:\Program Files (x86)\MySQL\MySQL Server 5.7\include/my_global.h: In function 'tm* localtime_r(const time_t*, tm*)':
C:\Program Files (x86)\MySQL\MySQL Server 5.7\include/my_global.h:644:25: error: 'localtime_s' was not declared in this scope
C:\Program Files (x86)\MySQL\MySQL Server 5.7\include/my_global.h: In function 'tm* gmtime_r(const time_t*, tm*)':
C:\Program Files (x86)\MySQL\MySQL Server 5.7\include/my_global.h:650:22: error: 'gmtime_s' was not declared in this scope
In file included from C:\Users\Sajith\Documents\CodeBlocks\mysqlconntest\main.cpp:3:0:
C:\Program Files (x86)\MySQL\MySQL Server 5.7\include/mysql.h: At global scope:
C:\Program Files (x86)\MySQL\MySQL Server 5.7\include/mysql.h:252:3: error: 'NET' does not name a type
C:\Program Files (x86)\MySQL\MySQL Server 5.7\include/mysql.h:277:25: error: 'SCRAMBLE_LENGTH' was not declared in this scope
C:\Program Files (x86)\MySQL\MySQL Server 5.7\include/mysql.h:415:48: error: use of enum 'enum_session_state_type' without previous declaration
C:\Program Files (x86)\MySQL\MySQL Server 5.7\include/mysql.h:419:47: error: use of enum 'enum_session_state_type' without previous declaration
C:\Program Files (x86)\MySQL\MySQL Server 5.7\include/mysql.h:441:45: error: use of enum 'mysql_enum_shutdown_level' without previous declaration
C:\Program Files (x86)\MySQL\MySQL Server 5.7\include/mysql.h:448:12: error: use of enum 'enum_mysql_set_option' without previous declaration
C:\Program Files (x86)\MySQL\MySQL Server 5.7\include/mysql.h:580:28: error: 'NET' has not been declared
C:\Program Files (x86)\MySQL\MySQL Server 5.7\include/mysql.h:634:21: error: 'MYSQL_ERRMSG_SIZE' was not declared in this scope
C:\Program Files (x86)\MySQL\MySQL Server 5.7\include/mysql.h:635:19: error: 'SQLSTATE_LENGTH' was not declared in this scope
Process terminated with status 1 (0 minute(s), 0 second(s))
15 error(s), 0 warning(s) (0 minute(s), 0 second(s))
Below are the things which I have done.
Went through this tutorial to create a libmysql.a file.
Verified my include directoried and linker libraries.
Linkers
Include Directories
This made me think that I didn't do my homework properly before I jumped into MySQL API programming. What am I missing here? What are the very basic things that I should ensure before I compile a MYSQL application. I was able to compile this program in my Linux machine successfuly. So I guess that this is Windows specific problem. Any help appreciated.
Note: I am using Code::Blocks (with MingGW toolchain) for an IDE and Windows 8.1 64Bit for an OS. MySQL is 32 bit and my application too is 32 bit.
With MinGW, you didn't need to create a glue. You could link the lib and dll files from MySQL to your C files. You can do it by adding the directory of the library files and the directory of the MySQL header files in your compilation. You could do it by gcc 'name.c' -o 'output.exe' -L "*Lib Directory*" -I "*Header Files Directory*"
Related
I try to cythonize a .py script. It is a PyQt5 gui with a large number of QToolButtons, and a working EventFilter. The c module is built successfully, however, the compilation fails with the following error:
d:\stuff\mapform2a.c(11338) : fatal error C1002: compiler is out of heap space in pass 2
LINK : fatal error LNK1257: code generation failed
error: command 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe' failed with exit status 1257
The compiler comes from Visual Studio 2019. Python 3.5.5 (yes, old, I know, but I have reasons...).
Is there any way to increase the heap space when trying to "cythonize -i script.py" ?
Cython documentation is really not clear on this (for a non-C-expert at least...)
EDIT
The full log is as follows:
C:\temp\MapForm>python setup.py build_ext --inplace Compiling
MapForm2A.py because it changed. [1/1] Cythonizing MapForm2A.py
C:\Anaconda3\lib\site-packages\Cython\Compiler\Main.py:369:
FutureWarning: Cython directive 'language_level' not set, using 2 for
now (Py2). This will change in a later release! File:
C:\temp\MapForm\MapForm2A.py tree = Parsing.p_module(s, pxd,
full_module_name) running build_ext building 'MapForm2A' extension
creating build creating build\temp.win-amd64-3.5 creating
build\temp.win-amd64-3.5\Release C:\Program Files (x86)\Microsoft
Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL
/DNDEBUG /MD -IC:\Anaconda3\include -IC:\Anaconda3\include
"-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE"
"-IC:\Program Files (x86)\Microsoft Visual Studio
14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt" "-IC:\Program Files (x86)\Windows
Kits\10\include\10.0.18362.0\shared" "-IC:\Program Files (x86)\Windows
Kits\10\include\10.0.18362.0\um" "-IC:\Program Files (x86)\Windows
Kits\10\include\10.0.18362.0\winrt" /TcMapForm2A.c
/Fobuild\temp.win-amd64-3.5\Release\MapForm2A.obj MapForm2A.c creating
C:\temp\MapForm\build\lib.win-amd64-3.5 C:\Program Files
(x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe /nologo
/INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO
/LIBPATH:C:\Anaconda3\libs /LIBPATH:C:\Anaconda3\PCbuild\amd64
"/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio
14.0\VC\LIB\amd64" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\LIB\amd64" "/LIBPATH:C:\Program Files
(x86)\Windows Kits\10\lib\10.0.18362.0\ucrt\x64" "/LIBPATH:C:\Program
Files (x86)\Windows Kits\10\lib\10.0.18362.0\um\x64"
/EXPORT:PyInit_MapForm2A
build\temp.win-amd64-3.5\Release\MapForm2A.obj
/OUT:build\lib.win-amd64-3.5\MapForm2A.cp35-win_amd64.pyd
/IMPLIB:build\temp.win-amd64-3.5\Release\MapForm2A.cp35-win_amd64.lib
MapForm2A.obj : warning LNK4197: export 'PyInit_MapForm2A' specified
multiple times; using first specification Creating library
build\temp.win-amd64-3.5\Release\MapForm2A.cp35-win_amd64.lib and
object build\temp.win-amd64-3.5\Release\MapForm2A.cp35-win_amd64.exp
Generating code c:\temp\mapform\mapform2a.c(7545) : fatal error C1002:
compiler is out of heap space in pass 2 LINK : fatal error LNK1257:
code generation failed error: command 'C:\Program Files
(x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe'
failed with exit status 1257
I can only add that the process gets stuck on the "Generating code" message for about 90 seconds before raising the C1002 exception.
The setup file is rather standard:
from setuptools import setup
from Cython.Build import cythonize
setup(
ext_modules = cythonize("MapForm2A.py")
)
The module is pure PyQt5 (pyuic5 output) with no other dependencies and works fine if interpreted directly with no Cython.
EDIT: SOLUTION (Maybe someone will need it).
Thanks to #DavidW (discussion in the comments below).
Setup.py has to be modified in the following way:
from distutils import _msvccompiler
_msvccompiler.PLAT_TO_VCVARS['win-amd64'] = 'amd64'
from setuptools import setup
from Cython.Build import cythonize
setup(
ext_modules = cythonize("MapForm2A.py"),
)
The first two lines force 64-bit toolchain.
For the purposes of giving a little more explanation to something solved in the comments: the basic problem looks to be that you're compiling something large and complicated and MSVC has run out of memory at the linking step.
Microsoft has a page about this error which suggests a number of options, with the main one being to use a 64-bit compiler. (Note that this is independent of whether you're compiling a 32-bit or 64-bit module - it's merely the choice of compiler executable)
When compiling Python extension modules (especially with setup.py) the compiler setup is typically selected by distutils. Unfortunately, it looks like distutils chooses to force a 32-bit compiler (see https://github.com/python/cpython/blob/e488e300f5c01289c10906c2e53a8e43d6de32d8/Lib/distutils/_msvccompiler.py#L160).
My suggestion was to dig into the distutils internals at the top of setup.py (before any real setup takes place) to override this setting
from distutils import _msvccompiler
_msvccompiler.PLAT_TO_VCVARS['win-amd64'] = 'amd64'
Essentially all you're really doing is passing the option amd64 to the vcvarsall.bat script that microsoft supply to set up their compiler, thus getting a 64-bit compiler to build a 64-bit extension.
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.
i'am using a Windows x64, i need to use Mysql 8 in QT 5.14.2( MinGW x64)
i've started installing MySQl driver as indicated :
2- then when, I am using:
cd $QTDIR/qtbase/src/plugins/sqldrivers/mysql
3- and run:
qmake -- MYSQL_INCDIR="C:\Program Files\MySQL\MySQL Server 8.0\include" "MYSQL_LIBDIR="C:\Program Files\MySQL\MySQL Server 8.0\lib"
I'm getting :
Project ERROR: Library 'mysql' is not defined.
in the log file it shows me that there's a missing file sybfront.h anyone knows how to solve this please
You should replace '\' by '/', either paths will be invalid, even on Windows.
And one quote " is not closed in your code.
qmake parameters follows the same rules as pro file contents:
https://doc.qt.io/qt-5/qmake-project-files.html
I have done android project in the mono develop It working fine in debug mode but when I am Trying to run project in release mode then it is giving following error:
C:\Users\Administrator.EDZ0138\Documents\Projects\IdooctopusNew\IdooctopusNew\SGEN: Error: Could not load file or assembly 'Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=c4c4237547e4b6cd' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A) (IdooctopusNew)
Can anyone please help me ?
I got a solution for this issue.
You just have to do is, put the mono.android.dll in to the C:\Program
Files\Microsoft SDKs\Windows\v7.0A\bin folder, open a command prompt and do
following steps:
cd C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin
sn -Vr Mono.Android.dll
gacutil -i C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin
Then build the project.
If you get the error for another DLL like System.xml.dll etc. then repeat above
procedure for respective DLL.
All the best.......!
I'm using Eclipse Juno CDT.
I added the following to my project:
the mysql/includes path to the includes path setting
the libmysql.lib and zlib.lib to libraries setting
the mysql library path to the library paths setting
Now, when I make my project, the compilation throws an error when I run the application.
This is the build:
10:08:56 **** Build of configuration Debug for project mysqlapp ****
make all
Building file: ../src/mysqlapp.c
Invoking: Cygwin C Compiler
gcc -I"C:\Program Files\MySQL\MySQL Connector C 6.0.2\include" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/mysqlapp.d" -MT"src/mysqlapp.d" -o "src/mysqlapp.o" "../src/mysqlapp.c"
cygwin warning:
MS-DOS style path detected: C:\Users\Yonaton\workspace\mysqlapp\Debug
Preferred POSIX equivalent is: /cygdrive/c/Users/Yonaton/workspace/mysqlapp/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
Finished building: ../src/mysqlapp.c
Building target: mysqlapp.exe
Invoking: Cygwin C Linker
gcc -L"C:\Program Files\MySQL\MySQL Connector C 6.0.2\lib\opt" -o "mysqlapp.exe" ./src/mysqlapp.o
Finished building target: mysqlapp.exe
And this is the run within eclipse:
10:09:55 **** Incremental Build of configuration Debug for project mysqlapp ****
make all
src/mysqlapp.d:1: *** multiple target patterns. Stop.
10:09:56 Build Finished (took 225ms)
Under Project->Properties->C/C++ General->Paths and Symbols->Libraries do not add the file name of the library, nor the path.
So if you want to link against /lib64/libz.so just add z.
Or alternativly add the z under Project->Properties->C/C++ Build->Settings->GCC Linker->Libraries.
If the library is not located under a standard path add the custom search path for a library under Project->Properties->C/C++ General->Paths and Symbols->Libraries Paths.
Update (referring "multiple target patterns"):
make does not like DOS paths. In the .d file a : after the drive letter is interpreted as target delimiter.
Switch to UNIX paths (as you were already told to do ... ;-)).
(see also: "multiple target patterns" Makefile error)
If I remember correctly "-l" ( small L) before your libraries.