Emscripten cant find mysql_driver.h when compiling

53 Views Asked by At

I am encountering an issue during the compilation process with Emscripten. The compiler is unable to find the 'mysql_driver.h' header file, resulting in a fatal error. I have already installed MySQL Connector/C++ on my system, and the necessary development files are present.

Here is the compilation command I'm using:

em++ main.cpp ../imgui/backends/imgui_impl_glfw.cpp ../imgui/backends/imgui_impl_opengl3.cpp ../imgui/imgui.cpp ../imgui/imgui_draw.cpp ../imgui/imgui_demo.cpp ../imgui/imgui_widgets.cpp ../imgui/imgui_tables.cpp -o imgui.js -I../imgui/imgui -I../imgui/backends -I/usr/include/cppconn -L/usr/lib -lmysqlcppconn -lglfw -lGL -g -s USE_WEBGL2=1 -s USE_GLFW=3 -s FULL_ES3=1 -O2 --preload-file data -s WASM=1

Besides, I have compiled another ImGUI project that uses Mysql the same way. And this command works just fine.

g++ -std=c++11 -I..//imgui -I..//backends -I/usr/include/cppconn -L/usr/lib -lmysqlcppconn -g -Wformat `pkg-config --cflags glfw3` -c -o main.o main.cpp

So I dont know what im doing wrong. I have compiled using verbose mode and this is the output. I have check the path of files, includes, routes and files. And everything is correct. Its just i cant compile.

Here is the verbose output:

"/usr/bin/clang++-13" -target wasm32-unknown-emscripten -DEMSCRIPTEN -D__EMSCRIPTEN_major__=3 -D__EMSCRIPTEN_minor__=1 -D__EMSCRIPTEN_tiny__=5 -fignore-exceptions -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -D_LIBCPP_ABI_VERSION=2 -fno-threadsafe-statics -Dunix -D__unix -D__unix__ -Werror=implicit-function-declaration -Xclang -iwithsysroot/include/SDL --sysroot=/usr/share/emscripten/cache/sysroot -Xclang -iwithsysroot/include/compat -I../imgui/imgui -I../imgui/backends -I/usr/include/cppconn -g -v -O2 main.cpp -c -o /tmp/emscripten_temp_70xlxuje/main_0.o
Ubuntu clang version 13.0.1-2ubuntu2.2
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /usr/bin
 (in-process)
 "/usr/lib/llvm-13/bin/clang" -cc1 -triple wasm32-unknown-emscripten -emit-obj --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model static -mframe-pointer=none -fno-rounding-math -mconstructor-aliases -target-cpu generic -debug-info-kind=constructor -dwarf-version=4 -debugger-tuning=gdb -v -fcoverage-compilation-dir=/home/clm/PiktoPark/src -resource-dir /usr/lib/llvm-13/lib/clang/13.0.1 -D EMSCRIPTEN -D __EMSCRIPTEN_major__=3 -D __EMSCRIPTEN_minor__=1 -D __EMSCRIPTEN_tiny__=5 -D _LIBCPP_ABI_VERSION=2 -D unix -D __unix -D __unix__ -I ../imgui/imgui -I ../imgui/backends -I /usr/include/cppconn -isysroot /usr/share/emscripten/cache/sysroot -internal-isystem /usr/share/emscripten/cache/sysroot/include/wasm32-emscripten/c++/v1 -internal-isystem /usr/share/emscripten/cache/sysroot/include/c++/v1 -internal-isystem /usr/lib/llvm-13/lib/clang/13.0.1/include -internal-isystem /usr/share/emscripten/cache/sysroot/include/wasm32-emscripten -internal-isystem /usr/share/emscripten/cache/sysroot/include -O2 -Werror=implicit-function-declaration -fdeprecated-macro -fdebug-compilation-dir=/home/clm/PiktoPark/src -ferror-limit 19 -fvisibility default -fgnuc-version=4.2.1 -fno-threadsafe-statics -fcxx-exceptions -fignore-exceptions -fexceptions -fcolor-diagnostics -vectorize-loops -vectorize-slp -iwithsysroot/include/SDL -iwithsysroot/include/compat -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -o /tmp/emscripten_temp_70xlxuje/main_0.o -x c++ main.cpp
clang -cc1 version 13.0.1 based upon LLVM 13.0.1 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "../imgui/imgui"
ignoring nonexistent directory "/usr/share/emscripten/cache/sysroot/include/wasm32-emscripten/c++/v1"
ignoring nonexistent directory "/usr/share/emscripten/cache/sysroot/include/wasm32-emscripten"
#include "..." search starts here:
#include <...> search starts here:
 ../imgui/backends
 /usr/include/cppconn
 /usr/share/emscripten/cache/sysroot/include/SDL
 /usr/share/emscripten/cache/sysroot/include/compat
 /usr/share/emscripten/cache/sysroot/include/c++/v1
 /usr/lib/llvm-13/lib/clang/13.0.1/include
 /usr/share/emscripten/cache/sysroot/include
End of search list.
main.cpp:7:10: fatal error: 'mysql_driver.h' file not found
#include <mysql_driver.h>
         ^~~~~~~~~~~~~~~~
1 error generated.
em++: error: '/usr/bin/clang++-13 -target wasm32-unknown-emscripten -DEMSCRIPTEN -D__EMSCRIPTEN_major__=3 -D__EMSCRIPTEN_minor__=1 -D__EMSCRIPTEN_tiny__=5 -fignore-exceptions -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -D_LIBCPP_ABI_VERSION=2 -fno-threadsafe-statics -Dunix -D__unix -D__unix__ -Werror=implicit-function-declaration -Xclang -iwithsysroot/include/SDL --sysroot=/usr/share/emscripten/cache/sysroot -Xclang -iwithsysroot/include/compat -I../imgui/imgui -I../imgui/backends -I/usr/include/cppconn -g -v -O2 main.cpp -c -o /tmp/emscripten_temp_70xlxuje/main_0.o' failed (returned 1)
make: *** [Makefile:22: imgui.js] Error 1

Also my project is based in this github where i just added the headers to the main.cpp. (The example IMGUI worked fine).

Also here is a minimal reproducible example with a compilation command.

#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
#include <stdio.h>
#include <iostream>
#include <mysql_driver.h>
#include <mysql_connection.h>
#include <cppconn/statement.h>
#include <cppconn/resultset.h>

using namespace sql;

extern "C"
{
    void connectToDatabase()
    {
        sql::mysql::MySQL_Driver *driver;
        sql::Connection *con;

        driver = sql::mysql::get_mysql_driver_instance();
        con = driver->connect("tcp://127.0.0.1:3306", "user", "password");
        delete con;
    }
}
//em++ -std=c++11 -s WASM=1 -s USE_PTHREADS=1 -o output.js main.cpp
0

There are 0 best solutions below