我是 C++ 新手,最近参加了一门课程向我介绍该语言,因此我了解了语法的基础知识,但没有讨论如何使用外部库并将它们连接到我们的代码。
我正在尝试使用 CLP COIN 库从...解决线性程序 http://www.coin-or.org/Clp/userguide/clpuserguide.html#id4766717
从我在那里读到的内容,它建议使用预编译的二进制库而不是下载源代码,因为我在 Windows 7 平台上,因为他们建议在 Windows 上重新编译有时会引入问题。
我只是想让相当于 Hello World 的工作。这是他们提供的用于测试的示例代码......
* Copyright (C) 2004, International Business Machines Corporation
and others. All Rights Reserved.
This sample program is designed to illustrate programming
techniques using CoinLP, has not been thoroughly tested
and comes without any warranty whatsoever.
You may copy, modify and distribute this sample program without
any restrictions whatsoever and without any payment to anyone.
*/
/* This shows how to provide a simple picture of a matrix.
The default matrix will print Hello World
*/
#include "ClpSimplex.hpp"
int main (int argc, const char *argv[])
{
ClpSimplex model;
int status;
// Keep names
if (argc<2) {
status=model.readMps("hello.mps",true);
} else {
status=model.readMps(argv[1],true);
}
if (status)
exit(10);
int numberColumns = model.numberColumns();
int numberRows = model.numberRows();
if (numberColumns>80||numberRows>80) {
printf("model too large\n");
exit(11);
}
printf("This prints x wherever a non-zero elemnt exists in matrix\n\n\n");
char x[81];
int iRow;
// get row copy
CoinPackedMatrix rowCopy = *model.matrix();
rowCopy.reverseOrdering();
const int * column = rowCopy.getIndices();
const int * rowLength = rowCopy.getVectorLengths();
const CoinBigIndex * rowStart = rowCopy.getVectorStarts();
x[numberColumns]='\0';
for (iRow=0;iRow<numberRows;iRow++) {
memset(x,' ',numberColumns);
for (int k=rowStart[iRow];k<rowStart[iRow]+rowLength[iRow];k++) {
int iColumn = column[k];
x[iColumn]='x';
}
printf("%s\n",x);
}
printf("\n\n");
return 0;
}
我已将 Include 和 Lib 目录与我在 Visual Studio 中的项目相关联,但是当我尝试构建时,会出现许多链接器错误,例如:
Simplex(void)" (??1ClpSimplex@@QAE@XZ) referenced in function _main
1>hello.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall CoinPackedMatrix::~CoinPackedMatrix(void)" (??1CoinPackedMatrix@@UAE@XZ) referenced in function _main
1>hello.obj : error LNK2019: unresolved external symbol "public: void __thiscall CoinPackedMatrix::reverseOrdering(void)" (?reverseOrdering@CoinPackedMatrix@@QAEXXZ) referenced in function _main
1>hello.obj : error LNK2019: unresolved external symbol "public: __thiscall CoinPackedMatrix::CoinPackedMatrix(class CoinPackedMatrix const &)" (??0CoinPackedMatrix@@QAE@ABV0@@Z) referenced in function _main
1>hello.obj : error LNK2019: unresolved external symbol "public: int __thiscall ClpSimplex::readMps(char const *,bool,bool)" (?readMps@ClpSimplex@@QAEHPBD_N1@Z) referenced in function _main
1>hello.obj : error LNK2019: unresolved external symbol "public: __thiscall ClpSimplex::ClpSimplex(bool)" (??0ClpSimplex@@QAE@_N@Z) referenced in function _main
作为一个新手,我对如何解决这个问题一无所知,因为我的课程只涉及与代码语法相关的调试,而不是链接器问题。
任何提示或指向其他线程的链接都会有很大帮助。我一直在谷歌上搜索一整天,但不知所措......