使用visual studio或cmake从源代码构建lib

时间:2016-04-21 15:57:05

标签: c++ visual-studio-2013 dll build

我正在尝试构建usrsctp库。使用cmake,它可以构建并且不会显示任何错误。使用nmake构建可以显示:

Microsoft (R) Program Maintenance Utility Version 11.00.60610.1
Copyright (C) Microsoft Corporation.  All rights reserved.

cl -DSCTP_DEBUG -DSCTP_SIMPLE_ALLOCATOR -DSCTP_PROCESS_LEVEL_LOCKS -D__Userspace__ -D__Userspace_os_Windows -DINET -DINET6 -D_LIB /I. /W3 /WX -c user_environment.c
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\cl.EXE"' : return code '0xc0000135'
Stop.

在cmake构建之后,我试图用dll_export_viewer查看其中的内容,并看到它是空的。我的问题是如何正确构建库(.lib)和/或(.dll)?

更新#1

CMake输出:

D:\Desktop\usrsctp>cmake -G "Visual Studio 12 2013" D:\Downloads\usrsctp-0.9.3.0\usrsctplib
-- The C compiler identification is MSVC 18.0.40629.0
-- The CXX compiler identification is MSVC 18.0.40629.0
-- Check for working C compiler using: Visual Studio 12 2013
-- Check for working C compiler using: Visual Studio 12 2013 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Visual Studio 12 2013
-- Check for working CXX compiler using: Visual Studio 12 2013 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of size_t
-- Check size of size_t - done
-- Check size of ssize_t
-- Check size of ssize_t - failed
-- Looking for sys/socket.h
-- Looking for sys/socket.h - not found
-- Looking for sys/queue.h
-- Looking for sys/queue.h - not found
-- Looking for linux/if_addr.h
-- Looking for linux/if_addr.h - not found
-- Looking for linux/rtnetlink.h
-- Looking for linux/rtnetlink.h - not found
-- Looking for netinet/ip_icmp.h
-- Looking for netinet/ip_icmp.h - not found
-- Looking for socket
-- Looking for socket - not found
-- Looking for inet_addr
-- Looking for inet_addr - not found
-- Performing Test HAVE_SA_LEN
-- Performing Test HAVE_SA_LEN - Failed
-- Performing Test HAVE_SIN_LEN
-- Performing Test HAVE_SIN_LEN - Failed
-- Performing Test HAVE_SIN6_LEN
-- Performing Test HAVE_SIN6_LEN - Failed
-- link library: ws2_32
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Desktop/usrsctp

Cmake构建输出:     D:\ Desktop \ usrsctp> cmake --build。     Microsoft(R)Build Engine版本12.0.40629.0     [Microsoft .NET Framework,版本4.0.30319.42000]     版权所有(C)Microsoft Corporation。保留所有权利。

Build started 2016-04-21 19:20:52.
Project "D:\Desktop\usrsctp\ALL_BUILD.vcxproj" on node 1 (default targets).
Project "D:\Desktop\usrsctp\ALL_BUILD.vcxproj" (1) is building             "D:\Desktop\usrsctp\ZERO_CHECK.vcxproj" (2) on node 1 (default targets).
PrepareForBuild:
....
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:29.86

使用DLL导出查看器enter image description here进行检查

2 个答案:

答案 0 :(得分:0)

问题是我的系统的PATH变量已损坏且nmake是从旧的Visual Studio版本运行的,该版本已被删除(为什么nmake不是我不知道)。修复之后,构建成功并且lib已完全实现

答案 1 :(得分:0)

这将超级依赖于您正在尝试构建的库。没有一种适合所有解决方案。 查看usrsctp的手册,您使用NMAKE所做的事情是有道理的。 我能给你的更多信息是关于你正在接收的错误。

https://msdn.microsoft.com/en-us/library/dt309377.aspx