jemalloc vs2013编译

下载

https://github.com/jemalloc/jemalloc

选择master

说明

本地解压后查看 jemalloc-master\msvc\ReadMe.txt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
How to build jemalloc for Windows
=================================

1. Install Cygwin with at least the following packages:
* autoconf
* autogen
* gawk
* grep
* sed

2. Install Visual Studio 2015 or 2017 with Visual C++

3. Add Cygwin\bin to the PATH environment variable

4. Open "x64 Native Tools Command Prompt for VS 2017"
(note: x86/x64 doesn't matter at this point)

5. Generate header files:
sh -c "CC=cl ./autogen.sh"

6. Now the project can be opened and built in Visual Studio:
msvc\jemalloc_vc2017.sln

安装cygwin

http://www.cygwin.com/ setup-x86.exe

环境配置

cygwin 默认安装完后,安装jemalloc说明在vs2013 的命令行下执行 sh -c “CC=cl ./autogen.sh” ,提示

1
2
3
autoconf
./autogen.sh: line 5: autoconf: command not found
Error 0 in autoconf

需要安装 autoconf2.5 、automake

upload successful

vs2015 工程降级

  • 修改 jemalloc_vc2015.sln

upload successful

  • 修改jemalloc.vcxproj

    1
    2
    3
    <?xml version="1.0" encoding="utf-8"?>
    <Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <ItemGroup Label="ProjectConfigurations">
  • vs2013 打开工程,修改平台工具集为“Visual Studio 2013 (v120)”

编译报错

static 正常;dll 库时报错

1
2
3
4
1>arena.obj : error LNK2001: 无法解析的外部符号 _test_hooks_arena_new_hook
1>malloc_io.obj : error LNK2001: 无法解析的外部符号 _test_hooks_libc_hook
1>pages.obj : error LNK2001: 无法解析的外部符号 _test_hooks_libc_hook
1>prof.obj : error LNK2001: 无法解析的外部符号 _test_hooks_libc_hook

添加 test_hooks.c 到工程中,重新编译

测试

能用,但是windows下替换malloc、free还不是很方便,下次尝试用下tcmalloc。

工程地址

链接:https://pan.baidu.com/s/1WsmfkgNSlIp_CYApYGUJ5Q
提取码:sgev