之前在GitHub上下载了一个开源工程,是用C语言写的需要编译静态库什么的以及生成一个exe文件。我用的是VisualStudio2015遇到了很多麻烦,一点经验都没有,所以记录了一下最终编译成功的这个过程。 我编译的是jmpeg工程,网上还有一个哥们和我的遭遇一样http://www.cnblogs.com/ubosm/p/5444919.html
1.没有在配置里面添加包含头文件的目录
错误 C1083 无法打开包括文件: “libwebsockets.h”: No such file or directory解决办法:打开工程配置–>>C/C++ –>>附加包含目录 D:\Output\VS2015\Project\jsmpeg-vnc-master\jsmpeg-vnc-master\source\libwebsocket
2.版本不兼容
错误 LNK2001 无法解析的外部符号 __imp__sprintf jsmpeg-vnc D:\Output\VS2015\Project\jsmpeg-vnc-master\jsmpeg-vnc-master\vs\websockets_static.lib(client-handshake.obj) 1分析:错误上写着websockets_static.lib这个静态库里面有无法解析的外部符号 原因:这是老外对这个问题解释的原话:
In visual studio 2015, stdin, stderr, stdout are defined as follow : #define stdin (__acrt_iob_func(0)) #define stdout (__acrt_iob_func(1)) #define stderr (__acrt_iob_func(2)) But previously, they were defined as: #define stdin (&__iob_func()[0]) #define stdout (&__iob_func()[1]) #define stderr (&__iob_func()[2]) So now __iob_func is not defined anymore which leads to a link error when using a .lib file compiled with previous versions of visual studio. To solve the issue, you can try defining __iob_func() yourself which should return an array containing {*stdin,*stdout,*stderr}. Regarding the other link errors about stdio functions (in my case it was sprintf()), you can add legacy_stdio_definitions.lib to your linker options.意思是说,VS2015的函数与前面版本定义的函数不一样才会报这个错。 解决方法: 打开工程配置–>>链接器 –>>附加依赖项添加下面这个库
legacy_stdio_definitions.lib3.版本不兼容
错误 LNK2019 无法解析的外部符号 __imp____iob_func,该符号在函数 _lwsl_emit_stderr 中被引用 jsmpeg-vnc D:\Output\VS2015\Project\jsmpeg-vnc-master\jsmpeg-vnc-master\vs\websockets_static.lib(libwebsockets.obj) 1在包含main函数的代码中添加
extern "C" { FILE __iob_func[3] = { *stdin,*stdout,*stderr }; }或者添加
#if _MSC_VER>=1900 #include "stdio.h" _ACRTIMP_ALT FILE* __cdecl __acrt_iob_func(unsigned); #ifdef __cplusplus extern "C" #endif FILE* __cdecl __iob_func(unsigned i) { return __acrt_iob_func(i); } #endif编译成功之后还要在目录下载添加相应的dll文件。并将client文件夹放到有exe文件的目录下面。运行即可。