0

It's in the title, I want to create a program in C which connects to my MySQL database which is hosted locally with MAMP, I use as IDE CLion and I'm on Windows. I also use the MySQL API that I installed in my MinGW directory

So to do this I use this code:

#include <stdio.h>
#include <stdlib.h>
#include <winsock.h>
#include <MYSQL/mysql.h>

int main(int argc, char **argv)
{
    printf("\nhello");
    MYSQL *con = mysql_init(NULL);

    if (con == NULL)
    {
        fprintf(stderr, "%s\n", mysql_error(con));
        exit(1);
    }

    printf("\ntest");
    if (mysql_real_connect(con, "localhost", "root", "root",
                           "perfect-concierge", 3307, NULL, 0) == NULL)
    {
        fprintf(stderr, "%s\n", mysql_error(con));
        mysql_close(con);
        exit(1);
    }
    printf("\ntest2");
    if (mysql_query(con, "CREATE DATABASE testdb"))
    {
        fprintf(stderr, "%s\n", mysql_error(con));
        mysql_close(con);
        exit(1);
    }
    printf("\ntest3");
    mysql_close(con);
    exit(0);
}

"Tests" are there to see where there would be an error. And I use this CMakeFile.txt :

cmake_minimum_required(VERSION 3.12)
project(Test-MySQL C)

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_FLAGS "-Wall")
add_library(libmysql SHARED IMPORTED)
set_target_properties(
        libmysql
        PROPERTIES LINKER_LANGUAGE C
        IMPORTED_IMPLIB "C:/MinGW/lib/libmysqlclient.a")
link_directories("C:/MinGW/lib")
add_executable(Test-MySQL main.c)
target_link_libraries(Test-MySQL libmysql)

(PS : It is not me who made this CMakeFile but the one who gave me this example of connection to a MySQL database)

But when I execute this code the program compiles well, it runs then I get this error :

Process finished with exit code -1073741515 (0xC0000135)

Without anything else. I tried to just change the main function and just keep printf("\nhello"); and the program worked correctly, but just add MYSQL *con = mysql_init(NULL); send me this error again

Thank you in advance for the time you will take to help me.

  • 1
    can you check the my.ini file if the port os really 3307 and not the standard 3306? – nbk Mar 11 '20 at 21:23
  • Perhaps, because you are importing a *static* library, you should use `STATIC`, not `SHARED`, in the `add_library()` command. – Kevin Mar 11 '20 at 21:23
  • Yes the good port is 3307, I don't know when it was modified but it is the right one. – JackAuxLanternes Mar 11 '20 at 21:55
  • I tried to replace `SHARED` with `STATIC` but during compilation it gave me this error : `CMakeFiles\Makefile2:74: recipe for target 'CMakeFiles/Test-MySQL.dir/all' failed` – JackAuxLanternes Mar 11 '20 at 21:57

2 Answers2

1

The error

Process finished with exit code -1073741515 (0xC0000135)

means that some .dll cannot be found when the executable is run (at runtime).

On Windows you need either

  1. Have directory with .dll (C:/MinGW/lib in your case) to be in your PATH variable.
  2. Have .dll itself near the executable (at the same directory). See that question for the way how to achieve that in CMake.

Note, that link_directories (and similar) affects only on search the library during the linking stage and doesn't help at runtime.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
0

MAMP is Macintosh, Apache, MySQL, Perl/Python/PHP. Which is the Apache as web server, MySQL as database server and Perl/Python/PHP as a module for the Web Server. Moreover, the important thing, MAMP is compatible in MacOS/Macintosh.

As your description, you are using Windows as the operating system, and C as your program language. So, for sure you can not use MAMP as your server.

Alternatively, You need to find any server that compatible for your Windows OS and your C as program language.

Hopefully it helps!

Agnes Palit
  • 246
  • 1
  • 5
  • 22
  • Sorry but the problem did not come from there, actually it does not seem logical seen like that, but the problem came from the fact that the executable could not find the dlls, but thank you anyway – JackAuxLanternes Mar 11 '20 at 23:56