在VS2010中使用CPLEX的访问冲突写入位置

Access Violation writing location using CPLEX with VS2010

本文关键字:访问冲突 位置 CPLEX VS2010      更新时间:2023-10-16

我是C编程新手。我在使用visual studio 2010的c++代码中运行CPLEX库。我在执行某些操作时遇到访问违规。

在CRT文件mlock.c中定义的void __cdecl _unlock函数中报告该违规。具体的行是leaveccriticalsection (_locktable[locknum])。锁);。

错误信息为Unhandled exception at 0x0f63443b: 0xC0000005: Access violation writing location 0xeb43c7c4。我的解释是,这是一个记忆相关的问题,但我不确定。此外,我不知道如何跟踪代码中的内存块0xeb43c7c4。

下面是调用栈:

    cplex124.dll!0fdd443b()     
    [Frames below may be incorrect and/or missing, no symbols loaded for cplex124.dll]  
    cplex124.dll!0fdd3bbb()     
    cplex124.dll!0fcd0610()     
    cplex124.dll!0fccfbfd()     
    cplex124.dll!0feb70fd()     
    cplex124.dll!0fede883()     
>   name.exe!_unlock(int locknum)  Line 375 C
    name.exe!_unlock_file2(int i, void * s)  Line 356 + 0x9 bytes   C
    name.exe!printf(const char * format, ...)  Line 68 + 0x10 bytes C
    name.exe!main(int argc, char * * argv)  Line 620 + 0xe bytes    C++
    name.exe!__tmainCRTStartup()  Line 278 + 0x12 bytes C
    kernel32.dll!7693ed6c()     
    ntdll.dll!7701377b()    
    ntdll.dll!7701374e() 

_unlock的源代码在mlock.c文件中:

void __cdecl _unlock (
        int locknum
        )
{
        /*
         * leave the critical section.
         */
        LeaveCriticalSection( _locktable[locknum].lock );
}

#ifdef _M_IX86
#pragma optimize("y",on)
#endif  /* _M_IX86 */

printf的源代码在printf.c文件中:

int __cdecl printf (
        const char *format,
        ...
        )
/*
 * stdout 'PRINT', 'F'ormatted
 */
{
    va_list arglist;
    int buffing;
    int retval;
    _VALIDATE_RETURN( (format != NULL), EINVAL, -1);
    va_start(arglist, format);
    _lock_str2(1, stdout);
    __try {
        buffing = _stbuf(stdout);
        retval = _output_l(stdout,format,NULL,arglist);
        _ftbuf(buffing, stdout);
    }
    __finally {
        _unlock_str2(1, stdout);
    }
    return(retval);
}

如果我在项目属性中删除音乐会文件的链接,我得到相同的错误信息,但在文件tidtable.c中,在_CRTIMP PFLS_GETVALUE_FUNCTION __cdecl __set_flsgetvalue()在线:PFLS_GETVALUE_FUNCTION flsGetValue = FLS_GETVALUE;

如有任何建议,我将不胜感激。

谢谢。

Cplex是一个商业求解器库。他们可能会发布您提到的几个不同版本的DLL,以符合各种构建类型。

此外,这种类型的库通常在您可以定义的预处理器定义方面给您提供了一点灵活性。有关详细信息,请参阅cplex文档。不匹配的定义会导致这样的错误,就像使用不支持多线程的运行时和支持多线程的库一样。

如果CPLEX被证明有问题,我还建议看看GLPK, GNU线性编程工具包作为一个开源的替代方案。