简体   繁体   English

如何获得通过终端编译的 C++ 代码以使用 Qt IDE 进行编译?

[英]How can I get C++ code that compiles via terminal to compile using the Qt IDE?

My general question is how can I get C++ code that compiles when I issue我的一般问题是如何获得在我发出时编译的 C++ 代码

g++ <my_program>.cpp -o my_program -O3 -ffast-math -lm -llapack -lgsl -lgslcblas

to build using the Qt IDE. The C++ code I have is written by my physics advisor and is for research that I'm conducting under his guidance, and I would like to be able to use a visual environment for changes I have to make.使用 Qt IDE 进行构建。我的 C++ 代码是由我的物理顾问编写的,用于我在他的指导下进行的研究,我希望能够使用可视化环境进行更改。 At the moment, my specific issue is (outside of the hundreds of warnings) one of the header files references several lapacke library functions that cause an "undefined reference" error.目前,我的具体问题是(在数百个警告之外)header 文件之一引用了几个导致“未定义引用”错误的 lapacke 库函数。 The offending line is:违规行是:

template <>
int tensor<double>::find_eigenvalues()
  {
   // some code
   // for loop
      {
         dsyevr_ (&JOBZ, &RANGE, &UPLO, &SIZE, A, &SIZE, &VLU, &VLU, &ILU, &ILU, &ABSTOL, &M, 
                  (double *)(obj->eval), Z, &LDZ, ISUPPZ, WORK, &LWORK, IWORK, &LIWORK, &INFO) ;
      }
   // more code
  }

Above this function definition appears上面这个function定义出现

extern "C" void dsyevr_ (char *, char *, char *, int *, double *, int *, double *, double *,
                         int *, int *, double *, int *, double *, double *, int *, int *,
                         double *, int *, int *, int *, int *) ;

Now, if I explicitly include the lapacke header file #include "lapacke.h" I can get rid of that error.现在,如果我明确包含 lapacke header 文件#include "lapacke.h" ,我就可以消除该错误。 However, a new one pops up.然而,一个新的弹出。 I get a "conflicting type" error from the line我从该行收到“冲突类型”错误

extern "C" void zheevr_ (char *, char *, char *, int *, complex *, int *, double *, double *, int *, int *, double *, int *, double *,
              complex *, int *, int *, complex *, int *, double *, int *, int *, int *, int *) ;

which is also a function that is defined in the lapacke.h header file.这也是在 lapacke.h header 文件中定义的 function。 Any help is appreciated!任何帮助表示赞赏!

My coding level would be school taught, but over 20 years since I've had a course in C++. I'm ok with basic notions, though.我的编码水平是学校教的,但自从我在 C++ 上过一门课程以来已有 20 多年了。不过我对基本概念没问题。

My version of Linux is: Ubuntu 18.04.5 x86_64.我的Linux版本是:Ubuntu 18.04.5 x86_64。 The g++ compiler version is: g++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0; g++编译版本为:g++(Ubuntu 7.5.0-3ubuntu1~18.04)7.5.0; which is also the kit I have selected for Qt.这也是我为 Qt 选择的套件。

I would strongly advise you to use CMake ( https://cmake.org/ ) to compile your project instead of using direct calls to the compiler.我强烈建议您使用CMake ( https://cmake.org/ ) 来编译您的项目,而不是直接调用编译器。 Using CMake will make it compatible with the QtCreator IDE while keeping it compilable through a command line as well.使用CMake 将使其与 QtCreator IDE 兼容,同时保持其可通过命令行进行编译。 CMake also manages dependencies such as your external libraries and is the most widely used build tool for C++. You can find many example to help you getting started if needed. CMake 还管理外部库等依赖项,是 C++ 使用最广泛的构建工具。如果需要,您可以找到许多示例来帮助您入门。 There are other build tools compatible with QtCreator, such as QMake or Qbs, but both are (unfortunately) less used than CMake.还有其他与 QtCreator 兼容的构建工具,例如 QMake 或 Qbs,但两者(不幸的是)都比 CMake 使用得少。

For your specific linking issue, you might need to add a -L option to locate your library file.对于您的特定链接问题,您可能需要添加一个 -L 选项来定位您的库文件。 (-L for the lib path, -l for the lib name). (-L 为 lib 路径,-l 为 lib 名称)。

In CMake, the commands that will interest you specifically are:在CMake中,你会特别感兴趣的命令是:

add_executable(..)
target_link_libraries(..)
target_include_directories(..)

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

相关问题 C ++程序在代码块中编译和运行,但无法在终端中编译 - C++ program compiles and runs in codeblocks, but can't compile it in terminal 如何在 Mac OS 上从 Visual Studio Code 编译 C++? (我只能通过终端来做) - How do I compile C++ from Visual Studio Code on Mac OS? (I can only do it via the terminal) 如何使用 Atom 编译 c++ opengl 代码? - How can I compile c++ opengl code using Atom? 如何通过终端编译C++代码 - how to compile C++ code through terminal 如何使用包装器从Swift调用C ++函数并使用终端进行编译? - How can I call C++ functions from Swift using a wrapper and compile using the terminal? 如何使用其他C ++程序编译C ++代码? - How can I compile C++ code using another C++ program? 如何通过Terminal Mac编译C ++程序 - How to compile a C++ program via Terminal Mac 编译C ++代码时出错“未定义引用”,但原始makefile代码编译 - Error “undefined reference to” when I compile a C++ code, but the original makefile code compiles Visual Studio IDE 如何仅使用一个按钮编译 C++ 代码? - How does Visual Studio IDE compile C++ code using just a button? 如何使用Emabarcadero C ++编译C源代码? - How can I compile C source code using Emabarcadero C++?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM