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.

 채택된 답변

Friedrich
Friedrich 2011년 7월 19일

0 개 추천

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

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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Deploy to C++ Applications Using mwArray API (C++03)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by