unresolved external symbol link error with R2009b and VC++2008 express sp1

Hello
I tried to start use c-mex function of Matlab recently. I use R2009b, and VC++2008 express sp1 for the c compliler. As I use just simple equations on c file, such as twotimes function, there is no problem.
However, when I use some external library for the simple socket programming, I got below link error messages.
--------------------------------------------
error LNK2019: unresolved external symbol __imp_listen referenced in function mdlInitializeConditions
---------------------------------------------
I read many useful helps in this site, and tried many things, but this error is not disappeared. It looks like I have to select library path for the Matlab. But I dont have any clues.
If someone answer how to solve this problem, it will be great help.

 Réponse acceptée

Friedrich
Friedrich le 19 Juil 2011
Hi,
without some more details it hard to tell whats wrong. Maybe the Microsoft doc can help:
You have to make sure that the compiler/linker can see the needed header and libraries. For this you have the -I and -L options in the mex command.

3 commentaires

Thank you Friedrich
I read the document of microsoft.
However, it looks like the library is not included by linker even now.
My purpose is to make a simple socket program using c-mex.
As you know, socket programming of Window needs the library of WS32_2.lib
For my case, the library is under "C:\Program Files\Microsoft SDKs\Windows\v7.0\Lib\x64"
I tried to set this folder as library folder using -L option following your advice. but I got a message as like below.
-----------------
>> mex -v sfun.c -LC:\Program Files\Microsoft SDKs\Windows\v7.0\Lib\x64 -l WS2_32.Lib
This is mex, Copyright 1984-2007 The MathWorks, Inc.
C:\PROGRA~1\MATLAB\R2009B\BIN\MEX.PL: Error: 'Files\Microsoft' not found.
------------------
It looks like the space is not allowed for the Matlab.
So, I moved all folders to the simple name, and tried again.
But, I got a message as like below.
------------------
>> mex sfun.c -LC:\user\sdk3_5\Lib -lWS2_32.lib
Warning: MEX could not find the library "WS2_32.lib"
specified with -l option on the path specified
with the -L option.
Creating library C:\USERS\SKKIM\APPDATA\LOCAL\TEMP\MEX_9B~1\templib.x and object C:\USERS\SKKIM\APPDATA\LOCAL\TEMP\MEX_9B~1\templib.exp
sfun.obj : error LNK2019: unresolved external symbol __imp_listen referenced in function mdlInitializeConditions
sfun.obj : error LNK2019: unresolved external symbol __imp_bind referenced in function mdlInitializeConditions
sfun.obj : error LNK2019: unresolved external symbol __imp_socket referenced in function mdlInitializeConditions
sfun.obj : error LNK2019: unresolved external symbol __imp_htonl referenced in function mdlInitializeConditions
sfun.obj : error LNK2019: unresolved external symbol __imp_htons referenced in function mdlInitializeConditions
sfun.obj : error LNK2019: unresolved external symbol __imp_WSAStartup referenced in function mdlInitializeConditions
sfun.mexw64 : fatal error LNK1120: 6 unresolved externals
C:\PROGRA~1\MATLAB\R2009B\BIN\MEX.PL: Error: Link of 'sfun.mexw64' failed.
-------------------------
I thought the Matlab did not recognize the library file.
If you inform me any clue, it would be great help.
Thanks
I am not a great friend of copying libraries. What happens when you compile it this way:
mex('-v','sfun.c','-LC:\Program Files\Microsoft SDKs\Windows\v7.0\Lib\x64','-lWS2_32')
Please do not specify the .lib since the doc states:
On Windows systems, name expands to name.lib or libname.lib and on UNIX systems, to libname.so or libname.dylib.
Your comment works perfectly.
I did not know .lib is not necessary.
Thank you! Fridrich

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by