简体   繁体   English

在命令提示符下使用 c++ postgresql 编译 JNI 文件出现致命错误

[英]Compiling a JNI file with c++ postgresql in command prompt getting fatal error

Command executed:执行的命令:

g++ -I"C:\Program Files\Java\jdk-16.0.2\include" -I"C:\Program Files\Java\jdk-16.0.2\include\win32" -I"C:\Program Files\libpqxx\include\pqxx" -shared -o hello.dll HelloJNI.cpp

pqxx file dir - C:\Program Files\libpqxx\include pqxx 文件目录 - C:\Program Files\libpqxx\include

I have included the path with -I .我已将路径包含在-I中。

I am using C++ for the backend connection for my Java program using JNI and unable to compile the cpp file, getting error as:我正在使用 C++ 为我的 Java 程序使用 JNI 进行后端连接,但无法编译 cpp 文件,出现以下错误:


HelloJNI.cpp:4:10: fatal error: pqxx/pqxx: No such file or director
    4 | #include <pqxx/pqxx>
      |          ^~~~~~~~~~~
compilation terminated.

The executed code is:执行的代码是:

#include <jni.h>       // JNI header provided by JDK
#include <iostream>    // C++ standard IO header
#include "HelloJNI.h"  // Generated
#include <pqxx/pqxx>
#include <string>
using namespace std;

// Implementation of the native method sayHello()
JNIEXPORT void JNICALL Java_HelloJNI_sayHello(JNIEnv *env, jobject thisObj) 
{
     try
    {
        std::string connectionString = "host=localhost port=5432 dbname=postgres user=postgres password =caNarain@2002";

        pqxx::connection connectionObject(connectionString.c_str());

        pqxx::work worker(connectionObject);

        pqxx::result response = worker.exec("SELECT * FROM books ORDER BY BOOK_ID");

        for (size_t i = 0; i < response.size(); i++)
        {
            std::cout << response[i][0] << " " << response[i][1] << " " << response[i][2] << " " << response[i][3] << " " << response[i][4] << " " << response[i][5] << std::endl;
        }

        return;
    }
    catch (const std::exception& e)
    {
        std::cerr << e.what() << std::endl;
    }

    system("pause");
}

Since you are using -I"C:\Program Files\libpqxx\include\pqxx" The #include should not be由于您使用的是 -I"C:\Program Files\libpqxx\include\pqxx" #include 不应该是

<pqxx/pqxx>

You can try -I"C:\Program Files\libpqxx\include" to make the search path consistent.您可以尝试 -I"C:\Program Files\libpqxx\include" 使搜索路径保持一致。

Compile the file in visual studio.在 Visual Studio 中编译文件。

Add the paths to the respective fields like additional include directories, linker files in the property.在属性中添加相应字段的路径,例如附加包含目录、链接器文件。

conclude the JNIEXPORT void JNICALL Java_HelloJNI_sayHello(JNIEnv *env, jobject thisObj)结束JNIEXPORT void JNICALL Java_HelloJNI_sayHello(JNIEnv *env, jobject thisObj)

inside a int main() method to compile since visual studio cannot compile the files without main method.int main()方法中进行编译,因为 Visual Studio 无法在没有 main 方法的情况下编译文件。

you can follow same as cmdline if your program doesn't have postgresql.如果您的程序没有 postgresql,您可以遵循与 cmdline 相同的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JNI编译致命错误:jni.h:没有这样的文件或目录 - JNI compiling fatal error: jni.h: No such file or directory 在命令提示符下使用MSBuild编译C ++代码时出错 - error in compiling c++ code using MSBuild from command prompt C ++编译致命错误 - C++ Compiling fatal error 通过命令提示符编译C ++项目 - Compiling c++ project through the command prompt 编译 C++ 程序时的致命错误 - a fatal error in compiling a c++ program JNI/C++编译问题 - JNI/C++ compiling problems 编写集成的 C/Java 程序并不断收到“致命错误:找不到‘jni.h’文件” - Writing an integrated C/Java program and keep getting “fatal error: 'jni.h' file not found” 使用Visual Studio devolopers命令提示符编译多源文件程序c ++ - compiling multiple-source-file programs c++ using visual studio devolopers command prompt Code::Blocks C++ 用 MacOS Mojave 编译:致命错误:sys/cdefs.h:没有这样的文件或目录 - Code::Blocks C++ compiling with MacOS Mojave : fatal error: sys/cdefs.h: No such file or directory 编译基于CMake的C ++项目时,“严重错误:找不到&#39;chrono&#39;文件” - “fatal error: 'chrono' file not found” when compiling C++ project based on CMake
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM