Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I fix fatal error C1113: #using failed on 'Mylib.lib'

Tags:

dll

c++-cli

.lib

I have a project which uses C++/CLI to implement a GUI and some background processing to talk to a sensor. I've got that all working and a lot of the comms stuff which we use to communicate the the sensor sits in a .dll. The problem is that I'd like to combine the library into the main executable to avoid having to worry about distributing .dlls.

I've got a demo project which works fine using a .lib but when I try and switch the mani code body to produce a .lib instead of .dll I get the following error:

1>------ Build started: Project: MyTool, Configuration: Debug Win32 ------
1>Compiling...
1>stdafx.cpp
1>.\stdafx.cpp : fatal error C1113: #using failed on 'c:\projects\MyTool\debug\MyLib.lib'

A bit of googling suggests this happens when you've not got the MSIL switch applied, but it's definitely in there in the library project.

I have a mixture of managed and unmanaged code in both my demo project and the real thing so I'm really struggling to see what the problem is here.

Any suggestions would be very gratefully received!

like image 535
Jon Cage Avatar asked Jan 22 '23 16:01

Jon Cage


2 Answers

I am guessing a bit, but I suspect the "MyTool" project has the "MyLib" project as one of its "references" ("Project" menu >> Properties >> Common Properties >> References).

When you change the type of the MyLib project to a LIB instead of a DLL, you need to remove "MyLib" from the project references. You then update the project dependencies of the solution ("Project" menu >> "Project Dependencies...") so that MyTool depends on MyLib.

like image 80
mcdave Avatar answered Jan 25 '23 06:01

mcdave


If you are linking to a mixed mode (managed/native) DLL you may get this error. Which you shouldn't if the project uses CLR even if one of the source files doesn't. But anyway, if that is the case, then try removing the reference from Project|Properties|Common Properties|References and then re-adding it.

like image 40
empty Avatar answered Jan 25 '23 06:01

empty