提问人:Sholi 提问时间:9/29/2018 更新时间:12/29/2018 访问量:399
mathGl / MinGW 未定义参考 Netbeans IDE
mathGl / MinGW undefined reference Netbeans IDE
问:
我正在尝试编译以下代码:
#include <cstdlib>
#define HAVE_STRUCT_TIMESPEC
#include <mgl2/mgl.h>
using namespace std;
int main() {
mglGraph gr;
gr.FPlot("sin(pi*x)");
gr.WriteFrame("test.png");
return 0;
}
我正在使用 Netbeans IDE、Win 10 64x ....但不断收到此错误:
感谢您的帮助。
cd 'C:\Users\SAQERpc\Documents\NetBeansProjects\Plotting'
C:\MinGW\msys\1.0\bin\make.exe -f Makefile CONF=调试
“/C/MinGW/msys/1.0/bin/make.exe” -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]:进入目录 /c/Users/SAQERpc/Documents/NetBeansProjects/Plotting'
mkdir -p 构建/调试/MinGW-Windows
rm -f “构建/调试/MinGW-Windows/main.o.d”
g++ -c -g -MMD -MP -MF “build/Debug/MinGW-Windows/main.o.d” -o build/Debug/MinGW-Windows/main.o main.cpp
mkdir -p dist/调试/MinGW-Windows
g++ -o dist/Debug/MinGW-Windows/plotting build/Debug/MinGW-Windows/main.o -lmgl
build/Debug/MinGW-Windows/main.o:在函数 _imp___ZTV8mglGraph' 中
c:/mingw/include/mgl2/mgl.h:42:对 _imp__mgl_create_graph' 的未定义引用
build/Debug/MinGW-Windows/main.o:在函数 _imp___ZTV8mglGraph' 中
c:/mingw/include/mgl2/mgl.h:53:对 _imp__mgl_delete_graph' 的未定义引用
build/Debug/MinGW-Windows/main.o:在函数 _imp__mgl_set_font_size' 中
build/Debug/MinGW-Windows/main.o:在函数 _imp__mgl_write_frame' 中
build/Debug/MinGW-Windows/main.o:在函数 _imp__mgl_fplot' 中
collect2.exe:错误:ld 返回 1 退出状态
make.exe[2]: * [dist/Debug/MinGW-Windows/plotting.exe] 错误 1
make.exe[2]:保留目录 /c/Users/SAQERpc/Documents/NetBeansProjects/Plotting'
make.exe[1]: *** [.build-conf] 错误 2
make.exe[1]:保留目录
/c/Users/SAQERpc/Documents/NetBeansProjects/Plotting'
make.exe“: * [.build-impl] 错误 2/c/Users/SAQERpc/Documents/NetBeansProjects/Plotting'
"/C/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/plotting.exe
make.exe[2]: Entering directory
ZN8mglGraphC1Eiii':
c:/mingw/include/mgl2/mgl.h:39: undefined reference to
_imp__mgl_create_graph_gl'
c:/mingw/include/mgl2/mgl.h:48: undefined reference to
ZN8mglGraphD1Ev':
c:/mingw/include/mgl2/mgl.h:53: undefined reference to
_imp__mgl_use_graph'
c:/mingw/include/mgl2/mgl.h:53: undefined reference to
ZN8mglGraph11SetFontSizeEd':
c:/mingw/include/mgl2/mgl.h:122: undefined reference to
ZN8mglGraph10WriteFrameEPKcS1_':
c:/mingw/include/mgl2/mgl.h:399: undefined reference to
ZN8mglGraph5FPlotEPKcS1_S1_':
c:/mingw/include/mgl2/mgl.h:1973: undefined reference to
构建失败(退出值 2,总时间:2 秒)
答:
您需要告诉链接器一个库名称,其中包含所有 mathGL 函数。在 Netbeans 8.2 中,您可以通过以下方式执行此操作(我假设您的项目是“C/C++ 应用程序”):
- 打开项目属性
- 单击左窗格中的“链接器”
- 找到“库”行,然后单击带有“...”的按钮在它的右侧
- 单击“添加选项...”在右窗格中
- 选择“其他选项”并键入“-lmgl”
- 点击“确定”
- 重新生成项目
最后一个弹出窗口,标题为“选择选项”,应如下所示:
也试试这个
Open your project properties
Click "Linker" in the left pane
Find "Libraries" line and click button with "..." on its right side
Click "Add option..." in the right pane
Select "Other Option" and type "-lodbc"
Click "Ok"
Rebuild your project
评论