ghandi Posted June 2, 2009 Posted June 2, 2009 (edited) Hi all,I've tried unsuccessfully on several occasions to compile C code to a static library so i can use it with MASM, but every time i try, i add the lib file to a project (created just for testing) and try to compile and i get the following error message:error LNK2001: unresolved external symbol _Function1@16I've used extern "C" to prevent the names being decorated, but this doesnt seem to make any difference to the error, as it is identical regardless of the name being decorated or not. I've tried using stdcall, no joy. Does anybody know what needs to be done to succeed with this?Also, i've succeeded in making a static library from a VC++ dll with Dll2Lib (an alternate approach i thought would be valid) once, but now when i try to do it with other dlls, i get the same error message as above. Does anybody have any experience with this and if so, how can i make the static libraries usable with MASM?It would be great if anyone can help me, please. HR,Ghandi Edited June 2, 2009 by ghandi
Ufo-Pu55y Posted June 2, 2009 Posted June 2, 2009 (edited) Did you try exporting your stuff simply via DEF file ?PS: Just tried myself.. indeed worked only after disabling a sh;tload of props in the project settings :|/editas I tried it myself anyway, check it out if you wanna: libby_test.7z Edited June 2, 2009 by Ufo-Pu55y
ghandi Posted June 4, 2009 Author Posted June 4, 2009 Thanks Ufo,Converting your project to VS2008 must have changed something, cos i've got the same issue, but i can compile the C code from commandline, so it is just an obj file. Then i can use that obj file when linking the MASM obj and it works fine.Because i use WinASM for an IDE, i had to find where you can edit the commandline passed to link.exe, which is in Project > Properties. It is here that i add the C obj file name and then i can build the project as per normal and it works fine.HR,Ghandi
ghandi Posted June 5, 2009 Author Posted June 5, 2009 Unsure what made a difference, but now all i need to do is use:extern "C" { // Function declarations go here}and now the compiled lib files work directly from VC++ to MASM. The only issue i have now is that i cant compile it with runtime as part of the library, because the heap initialization isnt performed, so calls to malloc will cause a crash. Is there a way i can get the C++ runtime to initialize? Otherwise i'll just stick to using it with multithread dll because msvcrt.dll ships with XP+ anyways.HR,Ghandi
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now