Why is the following error generated for 64-bit library: "module machine type 'x64' conflicts with target machine type 'X86'", then when switching to a 32-bit library this error is generated: "library machine type 'X86' conflicts with target match"?

21 views (last 30 days)
When using Simulink Real-Time, I am attempting to include some custom code with custom libraries as part of the build process. When I attempt to build the model, the following error is generated:
fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'X86'
This signifies that the libraries that are being used are 64-bit, but the target machine needs to use 32-bit libraries. I then switch over to use the 32-bit libraries, and when I attempt to build the following error is generated:
### Linking ...
link.exe /nologo /dll /MANIFEST /OPT:NOREF /export:mexFunction /export:mexfilerequiredapiversion /OUT:test_sfun.mexw64 /map:"test_sfun.map" @test_sfun.mol
Creating library test_sfun.lib and object test_sfun.exp
sIDN.obj : error LNK2019: unresolved external symbol viOD referenced in function sIDN
sIDN.obj : error LNK2019: unresolved external symbol viO referenced in function sIDN
sIDN.obj : error LNK2019: unresolved external symbol viC referenced in function sIDN
sIDN.obj : error LNK2019: unresolved external symbol viP referenced in function sIDN
sIDN.obj : error LNK2019: unresolved external symbol viS referenced in function sIDN
C:\custom_path\custom_library32.lib : warning LNK4272: library machine type 'X86' conflicts with target machine type 'x64'
test_sfun.mexw64 : fatal error LNK1120: 5 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\Bin\amd64\link.exe"' : return code '0x460'
I know that both of the libraries work with my custom code because I was able to compile using Microsoft Visual Studio 14.0 for both platforms, 64-bit and 32-bit.
How can I get my custom code to compile with my Simulink Real-Time model?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 13 Mar 2020
The Simulink Real-Time target is a 32-bit target, while the Simulink Model executed on a 64-bit host. For this reason, both the 32-bit and 64-bit libraries need to be provided for the build step of the application.
The easiest way to do this is to use legacy_code tool: https://www.mathworks.com/help/simulink/slref/legacy_code.html
Utilizing this tool, the libraries can be set individually for both the host and target using the following options:
HostLibFiles — A cell array of character vectors specifying library files required for host compilation. You can specify the library files using absolute or relative path names.
TargetLibFiles — A cell array of character vectors specifying library files required for target (that is, standalone) compilation. You can specify the library files using absolute or relative path names.
In this situation the HostLibFiles will be x64 and the TargetLibFiles will be x32.

More Answers (0)

Categories

Find more on Troubleshooting in Simulink Real-Time in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!