External header file ilcplex\cpxconst.h causing causing compiler error

半世苍凉 提交于 2021-02-13 17:28:10

问题


I have been sent code for a program built in C that uses a reinforcement learning algorithm. I need to modify it, yet I am having difficulties with compiling the code in the first place. Here are the outputs in CodeBlocks.

All errors come from one line of code in a header file, which is part of the IBM CPLEX include directory (include\cplex\cpxconst.h)

The line of code in question is as follows.

define CPXDEPRECATEDAPI(version) __declspec(dllimport deprecated)

error messages are multiple types of syntax errors such as: error: expected identifier or '(' before ')' token

Each error has notes: to multiple lines of code in the file ilcplex\cplex.h

I am using CodeBlocks in Windows 10 CPLEX version is 12.9.0

FULL ERROR MESSAGE

||=== Build: Release in SWEM2020 (compiler: GNU GCC Compiler) ===| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cpxconst.h|243|error: expected ')' before 'deprecated'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cplex.h|1194|note: in expansion of macro 'CPXDEPRECATEDAPI'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cpxconst.h|243|error: expected identifier or '(' before ')' token| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cplex.h|1194|note: in expansion of macro 'CPXDEPRECATEDAPI'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cpxconst.h|243|error: expected ')' before 'deprecated'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cplex.h|1200|note: in expansion of macro 'CPXDEPRECATEDAPI'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cpxconst.h|243|error: expected identifier or '(' before ')' token| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cplex.h|1200|note: in expansion of macro 'CPXDEPRECATEDAPI'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cpxconst.h|243|error: expected ')' before 'deprecated'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cplex.h|1231|note: in expansion of macro 'CPXDEPRECATEDAPI'| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\swemextras.h|16|error: conflicting types for 'trunc'| c:\mingw\include\math.h|820|note: previous declaration of 'trunc' was here| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cpxconst.h|243|error: expected ')' before 'deprecated'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cplex.h|1194|note: in expansion of macro 'CPXDEPRECATEDAPI'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cpxconst.h|243|error: expected identifier or '(' before ')' token| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cplex.h|1194|note: in expansion of macro 'CPXDEPRECATEDAPI'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cpxconst.h|243|error: expected ')' before 'deprecated'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cplex.h|1200|note: in expansion of macro 'CPXDEPRECATEDAPI'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cpxconst.h|243|error: expected identifier or '(' before ')' token| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cplex.h|1200|note: in expansion of macro 'CPXDEPRECATEDAPI'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cpxconst.h|243|error: expected ')' before 'deprecated'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cplex.h|1231|note: in expansion of macro 'CPXDEPRECATEDAPI'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cpxconst.h|243|error: expected identifier or '(' before ')' token| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cplex.h|1231|note: in expansion of macro 'CPXDEPRECATEDAPI'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cpxconst.h|243|error: expected ')' before 'deprecated'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cplex.h|1237|note: in expansion of macro 'CPXDEPRECATEDAPI'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cpxconst.h|243|error: expected identifier or '(' before ')' token| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cplex.h|1237|note: in expansion of macro 'CPXDEPRECATEDAPI'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cpxconst.h|243|error: expected ')' before 'deprecated'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cplex.h|1242|note: in expansion of macro 'CPXDEPRECATEDAPI'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cpxconst.h|243|error: expected identifier or '(' before ')' token| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cplex.h|1242|note: in expansion of macro 'CPXDEPRECATEDAPI'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cpxconst.h|243|error: expected ')' before 'deprecated'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cplex.h|1597|note: in expansion of macro 'CPXDEPRECATEDAPI'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cpxconst.h|243|error: expected identifier or '(' before ')' token| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cplex.h|1597|note: in expansion of macro 'CPXDEPRECATEDAPI'| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\alg_genetic1.c||In function 'GeneticAlgorithm1':| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\alg_genetic1.c|64|warning: too many arguments for format [-Wformat-extra-args]| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\alg_genetic1.c|67|warning: unused variable 'lostLoad' [-Wunused-variable]| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\dlist.c|137|error: conflicting types for 'InsertInOrder_dlist'| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\dlist.h|19|note: previous declaration of 'InsertInOrder_dlist' was here| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cpxconst.h|243|error: expected identifier or '(' before ')' token| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cplex.h|1231|note: in expansion of macro 'CPXDEPRECATEDAPI'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cpxconst.h|243|error: expected ')' before 'deprecated'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cplex.h|1237|note: in expansion of macro 'CPXDEPRECATEDAPI'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cpxconst.h|243|error: expected identifier or '(' before ')' token| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cplex.h|1237|note: in expansion of macro 'CPXDEPRECATEDAPI'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cpxconst.h|243|error: expected ')' before 'deprecated'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cplex.h|1242|note: in expansion of macro 'CPXDEPRECATEDAPI'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cpxconst.h|243|error: expected identifier or '(' before ')' token| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cplex.h|1242|note: in expansion of macro 'CPXDEPRECATEDAPI'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cpxconst.h|243|error: expected ')' before 'deprecated'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cplex.h|1597|note: in expansion of macro 'CPXDEPRECATEDAPI'| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cpxconst.h|243|error: expected identifier or '(' before ')' token| C:\Program Files\IBM\ILOG\CPLEX_Studio_Community129\cplex\include\ilcplex\cplex.h|1597|note: in expansion of macro 'CPXDEPRECATEDAPI'| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\swemextras.h|16|error: conflicting types for 'trunc'| c:\mingw\include\math.h|820|note: previous declaration of 'trunc' was here| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\alg_rf.c||In function 'RFAlgorithm1':| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\alg_rf.c|183|warning: too many arguments for format [-Wformat-extra-args]| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\alg_rf.c|185|warning: unused variable 'lostLoad' [-Wunused-variable]| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\alg_rf.c||In function 'Alg_MERwFirms_MustRun':| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\alg_rf.c|466|warning: unused variable 'lostLoad' [-Wunused-variable]| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\alg_rf.c||In function 'Alg_MERwFirms':| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\alg_rf.c|727|warning: too many arguments for format [-Wformat-extra-args]| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\alg_rf.c|729|warning: unused variable 'lostLoad' [-Wunused-variable]| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\alg_rf.c||In function 'Alg_MERwFirmsSoftmax':| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\alg_rf.c|934|warning: too many arguments for format [-Wformat-extra-args]| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\alg_rf.c|936|warning: unused variable 'lostLoad' [-Wunused-variable]| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\alg_rf.c||In function 'Alg_ERSpilloverwFirms':| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\alg_rf.c|1179|warning: too many arguments for format [-Wformat-extra-args]| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\alg_rf.c|1181|warning: unused variable 'lostLoad' [-Wunused-variable]| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\alg_rf.c||In function 'Alg_ERSpilloverwFirmsSoftmax':| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\alg_rf.c|1393|warning: too many arguments for format [-Wformat-extra-args]| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\alg_rf.c|1395|warning: unused variable 'lostLoad' [-Wunused-variable]| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\alg_rf.c||In function 'RFAlgorithm':| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\alg_rf.c|1573|warning: too many arguments for format [-Wformat-extra-args]| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\alg_rf.c|1575|warning: unused variable 'lostLoad' [-Wunused-variable]| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\alg_rf.c||In function 'RFAlgorithmM':| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\alg_rf.c|1784|warning: too many arguments for format [-Wformat-extra-args]| C:\Users\Tingle\OneDrive\Documents\Coding\SWEM2020\alg_rf.c|1786|warning: unused variable 'lostLoad' [-Wunused-variable]| ||=== Build failed: 27 error(s), 17 warning(s) (0 minute(s), 2 second(s)) ===|


回答1:


This answer is very similar to the one I gave here: C++: Cplex/cp optimizer makefile issues on project build using Clion with MinGW and g++ compiler

The CPLEX detailed system requirements (click on "Version 12.9.0" > "Windows" > "Prerequisites") show that Visual Studio 2015-2019 are the only supported compilers on Windows.

If we look at cpxconst.h, line 243 (from your error message), code in question we see:

#   if defined(_WIN32) && !defined(BUILD_CPXSTATIC)
#      define CPXLIBAPI __declspec(dllimport)
#      define CPXDEPRECATEDAPI(version) __declspec(dllimport deprecated)
#      define CPXDEPRECATED(version) __declspec(deprecated)
...
#   endif

Based on this, it looks like your MinGW gcc has _WIN32 defined and it's defining CPXDEPRECATEDAPI in such a way that is only compatible with Microsoft Visual C.

You could replace the definition of CPXDEPRECATEDAPI with a no-op (i.e., edit cpxconst.h, like so:

#      define CPXDEPRECATEDAPI(version)

However, you are likely to just end up running into some other error down the line.

On Windows, you should really just use Visual Studio 2015 or above, or perhaps consider using the WSL.



来源:https://stackoverflow.com/questions/61182200/external-header-file-ilcplex-cpxconst-h-causing-causing-compiler-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!