cpp_example.obj:错误LNK2001:未解析的外部符号_IpoptApplicationFactory [英] cpp_example.obj : error LNK2001: unresolved external symbol _IpoptApplicationFactory
问题描述
Hello
我正在尝试使用IPOPT.dll运行一个示例,但我一直收到此链接错误。
I am trying to run an example using IPOPT.dll but i keep getting this link error.
cpp_example。 obj:错误LNK2001:未解析的外部符号_IpoptApplicationFactory
cpp_example.obj : error LNK2001: unresolved external symbol _IpoptApplicationFactory
我已将附加依赖项中的IpOpt-vc10.lib与VC ++目录中include目录中的include(头文件)相链接。
I have linked the IpOpt-vc10.lib in the Additional Dependencies and the include (header files ) in the include directories in VC++directories.
//cpp_example.cpp
#include "IpIpoptApplication.hpp"
#include "IpSolveStatistics.hpp"
#include "MyNLP.hpp"
#include <iostream>
using namespace Ipopt;
int main(int argv, char* argc[])
{
// Create an instance of your nlp...
SmartPtr<TNLP> mynlp = new MyNLP();
// Create an instance of the IpoptApplication
//
// We are using the factory, since this allows us to compile this
// example with an Ipopt Windows DLL
SmartPtr<IpoptApplication> app = IpoptApplicationFactory();
// Initialize the IpoptApplication and process the options
ApplicationReturnStatus status;
status = app->Initialize();
if (status != Solve_Succeeded) {
std::cout << std::endl << std::endl << "*** Error during initialization!" << std::endl;
return (int) status;
}
status = app->OptimizeTNLP(mynlp);
if (status == Solve_Succeeded) {
// Retrieve some statistics about the solve
Index iter_count = app->Statistics()->IterationCount();
std::cout << std::endl << std::endl << "*** The problem solved in " << iter_count << " iterations!" << std::endl;
Number final_obj = app->Statistics()->FinalObjective();
std::cout << std::endl << std::endl << "*** The final value of the objective function is " << final_obj << '.' << std::endl;
}
return (int) status;
}
任何指导都将不胜感激。
Any guidance would be appreciated.
提前致谢。
推荐答案
你好pavithrasekar11,
Hi pavithrasekar11,
感谢您在这里发帖。
>> cpp_example.obj:错误LNK2001:未解析的外部符号_IpoptApplicationFactory
>>cpp_example.obj : error LNK2001: unresolved external symbol _IpoptApplicationFactory
看来你在不使用
extern
"C"的情况下从C ++程序调用C函数。 (这会导致编译器使用C命名约定)可能导致LNK2001。
It seems that you're calling a C function from a C++ program without using
extern
"C" (which causes the compiler to use the C naming convention) can cause LNK2001.
编译器选项
/ Tp 和
< span style ="color:#0066cc"> / Tc 使编译器分别将文件编译为C ++或C,而不管文件扩展名是什么。这些选项可能导致函数名称与您的预期不同。
Compiler options /Tp and /Tc cause the compiler to compile files as C++ or C, respectively, regardless of the filename extension. These options can cause function names different from what you expect.
由于其他可能的原因,请参阅下面的文档。
For other possible reasons, please refer to this document below.
https://msdn.microsoft.com/en-us/library/f6xx1b1z.aspx
希望这可以帮助你。
最好的问候,
Sera Yu
这篇关于cpp_example.obj:错误LNK2001:未解析的外部符号_IpoptApplicationFactory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!