提问人:mdslt 提问时间:10/24/2022 最后编辑:mdslt 更新时间:10/24/2022 访问量:73
为什么 c++ 在包含其目录时无法定义对 gurobi 函数的引用?
Why does c++ cannot define references to gurobi's functions while its directories are included?
问:
我正在尝试在 Windows 952 上安装 gurobi 10 for (CLion)。我有一个有效的 gurobi 许可证(它适用于 Java 和 Python),但是,我无法在 .我在互联网上寻找解决方案并找到了几个主题,但没有一个有解决方案,尤其是对于 Windows 用户。
我创建了如下内容:c++
c++
CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
project(CHEO)
set(CMAKE_CXX_STANDARD 20)
include_directories(C:/gurobi952/win64/include)
add_executable(CHEO main.cpp)
另外,我正在初始化 gurobi 主文件,如下所示:
#include "iostream"
#include "gurobi_c++.h"
using namespace std;
int
main(int argc,
char *argv[])
{
try {
cout << "Hello" << endl;
// Create an environment
GRBEnv env = GRBEnv(true);
} catch(...) {
cout << "Exception during optimization" << endl;
}
return 0;
}
但是,我遇到一个错误,说:
[1/2] Building CXX object CMakeFiles/CHEO.dir/main.cpp.obj
[2/2] Linking CXX executable CHEO.exe
FAILED: CHEO.exe
cmd.exe /C "cd . && C:\PROGRA~1\JETBRA~1\CLION2~1.4\bin\mingw\bin\G__~1.EXE -g CMakeFiles/CHEO.dir/main.cpp.obj -o CHEO.exe -Wl,--out-implib,libCHEO.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
C:\Program Files\JetBrains\CLion 2022.2.4\bin\mingw\bin/ld.exe: CMakeFiles/CHEO.dir/main.cpp.obj:C:/Users/USERNAME/CLionProjects/CHEO/main.cpp:12: undefined reference to `GRBEnv::GRBEnv(bool)'
C:\Program Files\JetBrains\CLion 2022.2.4\bin\mingw\bin/ld.exe: CMakeFiles/CHEO.dir/main.cpp.obj: in function `main':
C:/Users/USERNAME/CLionProjects/CHEO/main.cpp:48: undefined reference to `GRBEnv::~GRBEnv()'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
此外,我还尝试了此处提供的解决方案(gurobi 的支持网站)。但是,一旦我将建议的文件包含在我的项目(和)的目录中,我在编译文件时会遇到以下错误:CMakeLists.txt
FindGUROBI.cmake
CMakeLists.txt
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
GUROBI_CXX_LIBRARY
linked by target "gurobi-template" in directory C:/Users/USERNAME/CLionProjects/CHEO
linked by target "gurobi-template" in directory C:/Users/USERNAME/CLionProjects/CHEO
对于Windows用户来说,这个问题的解决方案是什么?感谢您的耐心等待,因为我是新手。c++
答: 暂无答案
评论
include_directory