MacOS 10.15编译openjdk8u详细过程-程序员宅基地

技术标签: Java  openjdk  macOS  

MacOS 10.15编译openjdk8u详细过程

三年前编译过一次openjdk8,最近需要调试,发现当时编译时没加调试信息,于是准备重新编译,由于机器信息与三年前完全不同,编译时的异常超出我预期,经过一周折腾终于编译通过,以下上本次编译的详细过程,希望对大家避坑有帮助

环境

1. 机器环境信息

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

JVM输出系统信息
OS:Bsduname:Darwin 19.4.0 Darwin Kernel Version 19.4.0: Wed Mar  4 22:28:40 PST 2020; root:xnu-6153.101.6~15/RELEASE_X86_64 x86_64
rlimit: STACK 8192k, CORE 0k, NPROC 2784, NOFILE 10240, AS infinity

CPU:total 4 (initial active 4) (2 cores per cpu, 2 threads per core) family 6 model 78 stepping 3, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1, sse4.2, popcnt, avx, avx2, aes, clmul, erms, rtm, 3dnowpref, lzcnt, ht, tsc, tscinvbit, bmi1, bmi2, adx

Memory: 4k page, physical 16777216k(369628k free)

2.依赖软件安装

  1. Boot-strap JDK : jdk-7u80-macosx-x64.dmg

  2. XQuartz : XQuartz-2.7.11.dmg

  3. brew 安装以下软件

    brew install freetype
    brew install ant
    brew install ccache
    brew install autoconf
    brew install llvm
    brew install binutils
    
  4. 期间为了解决问题安装过[email protected]和gcc@7没有使用到

准备

1. mercurial安装

lizhengdeMacBook-Pro:homebrew-core lizheng$ brew install mercurial

2. 代码下载

直接从源码库克隆源码,然后使用命令下载代码

hg clone http://hg.openjdk.java.net/jdk8u/jdk8u jdk8u
hg pull
vim batchget.sh
chmod +x batchget.sh 
./batchget.sh 

如果网速不好可以参考网上另一篇文篇,使用批量脚本(batchget.sh),脚本如下

#!/bin/bash

for i in {
    1..28}
do
sh ./get_source.sh;
done

3. 查看configure帮助

lizhengdeMacBook-Pro:openjdk8 lizheng$ bash configure --help
Running generated-configure.sh

4.安装配置

./configure --with-xcode-path --with-debug-level=slowdebug --with-boot-jdk=`/usr/libexec/java_home -v 1.7`   --enable-debug-symbols --disable-zip-debug-info --with-memory-size=6144 ZIP_DEBUGINFO_FILES=0  OBJCOPY=gobjcopy  --with-jobs=8 CC=clang CXX=clang++  --with-native-debug-symbols=internal

configure有不少的参数, 具体的参数可以通过 'bash ./configure --help' 查看
   --with-debug-level=slowdebug   表示构建debug版本, openjdk8去掉了jvmg版本的构建
   --enable-debug-symbols 和   ZIP_DEBUGINFO_FILES=0  主要是方便调试
   

运行输出:

lizhengdeMacBook-Pro:jdk8uuu lizheng$ ./configure --with-xcode-path --with-debug-level=slowdebug --with-boot-jdk=`/usr/libexec/java_home -v 1.7`   --enable-debug-symbols --disable-zip-debug-info --with-memory-size=6144 ZIP_DEBUGINFO_FILES=0  OBJCOPY=gobjcopy  --with-jobs=8 CC=clang CXX=clang++  --with-native-debug-symbols=internal
Configure source code has been updated, checking time stamps
Running generated-configure.sh
configure: Configuration created at Mon Apr 20 09:28:00 CST 2020.
configure: configure script generated at timestamp 1585090987.


====================================================
A new configuration has been successfully created in
/Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uuu/build/macosx-x86_64-normal-server-slowdebug
using configure arguments '--with-xcode-path --with-debug-level=slowdebug --with-boot-jdk=/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home --enable-debug-symbols --disable-zip-debug-info --with-memory-size=6144 ZIP_DEBUGINFO_FILES=0 OBJCOPY=gobjcopy --with-jobs=8 CC=clang CXX=clang++ --with-native-debug-symbols=internal'.

Configuration summary:
* Debug level:    slowdebug
* JDK variant:    normal
* JVM variants:   server
* OpenJDK target: OS: macosx, CPU architecture: x86, address length: 64

Tools summary:
* Boot JDK:       java version "1.7.0_80" Java(TM) SE Runtime Environment (build 1.7.0_80-b15) Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)  (at /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home)
* Toolchain:      gcc (GNU Compiler Collection)
* C Compiler:     Version clang version 10.0.0 Target: x86_64-apple-darwin19.4.0 Thread model: posix InstalledDir: /usr/local/opt/llvm/bin (at /usr/local/opt/llvm/bin/clang)
* C++ Compiler:   Version clang version 10.0.0 Target: x86_64-apple-darwin19.4.0 Thread model: posix InstalledDir: /usr/local/opt/llvm/bin (at /usr/local/opt/llvm/bin/clang++)

Build performance summary:
* Cores to use:   8
* Memory limit:   6144 MB

lizhengdeMacBook-Pro:tmp lizheng$ git clone https://github.com/imkiwa/xcode-missing-libstdc-.git
Cloning into 'xcode-missing-libstdc-'...
remote: Enumerating objects: 597, done.
remote: Counting objects: 100% (597/597), done.
remote: Compressing objects: 100% (232/232), done.
remote: Total 597 (delta 362), reused 597 (delta 362), pack-reused 0
Receiving objects: 100% (597/597), 876.56 KiB | 56.00 KiB/s, done.
Resolving deltas: 100% (362/362), done.

lizhengdeMacBook-Pro:tmp lizheng$ sudo mkdir -p Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++
lizhengdeMacBook-Pro:tmp lizheng$ sudo cp -R xcode-missing-libstdc-/include/c++/* /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++
lizhengdeMacBook-Pro:tmp lizheng$ sudo cp xcode-missing-libstdc-/lib/*  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/

5.构建

lizhengdeMacBook-Pro:jdk8uuu lizheng$ make all JOBS=8 ZIP_DEBUGINFO_FILES=0 COMPILER_WARNINGS_FATAL=false  CC=clang USE_CLANG=true LP64=1

构建输出:

Building OpenJDK for target 'all' in configuration 'macosx-x86_64-normal-server-slowdebug'

## Starting langtools
Compiling 2 files for BUILD_TOOLS
Compiling 32 properties into resource bundles
Compiling 782 files for BUILD_BOOTSTRAP_LANGTOOLS
注: 某些输入文件使用或覆盖了已过时的 API。
注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。
Creating langtools/dist/bootstrap/lib/javac.jar
Updating langtools/dist/lib/src.zip
Compiling 785 files for BUILD_FULL_JAVAC
注: 某些输入文件使用或覆盖了已过时的 API。
注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。
Creating langtools/dist/lib/classes.jar
## Finished langtools (build time 00:00:40)

## Starting hotspot
Compiling /Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uuu/hotspot/src/share/vm/adlc/adlparse.cpp
Compiling /Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uuu/hotspot/src/share/vm/adlc/archDesc.cpp
Compiling /Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uuu/hotspot/src/share/vm/adlc/arena.cpp
Compiling /Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uuu/hotspot/src/share/vm/adlc/dfa.cpp
clang-10: warning: include path for libstdc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
clang-10: warning: include path for libstdc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
clang-10: warning: include path for libstdc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
Compiling /Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uuu/hotspot/src/share/vm/adlc/dict2.cpp
In file included from /Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uuu/hotspot/src/share/vm/adlc/arena.cpp:25:
/Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uuu/hotspot/src/share/vm/adlc/adlc.hpp:36:10: fatal error: 'iostream' file not found
#include <iostream>
         ^~~~~~~~~~
clang-10: warning: include path for libstdc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
Compiling /Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uuu/hotspot/src/share/vm/adlc/filebuff.cpp
In file included from /Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uuu/hotspot/src/share/vm/adlc/adlparse.cpp:27:
/Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uuu/hotspot/src/share/vm/adlc/adlc.hpp:36:10: fatal error: 'iostream' file not found
#include <iostream>
         ^~~~~~~~~~
In file included from /Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uuu/hotspot/src/share/vm/adlc/archDesc.cpp:27:
/Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uuu/hotspot/src/share/vm/adlc/adlc.hpp:36:10: fatal error: 'iostream' file not found
#include <iostream>
         ^~~~~~~~~~
Compiling /Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uuu/hotspot/src/share/vm/adlc/forms.cpp
clang-10: warning: include path for libstdc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
clang-10: warning: include path for libstdc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
clang-10: warning: include path for libstdc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
In file included from /Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uuu/hotspot/src/share/vm/adlc/dfa.cpp:26:
/Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uuu/hotspot/src/share/vm/adlc/adlc.hpp:36:10: fatal error: 'iostream' file not found
#include <iostream>
         ^~~~~~~~~~
In file included from /Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uuu/hotspot/src/share/vm/adlc/forms.cpp:26:
/Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uuu/hotspot/src/share/vm/adlc/adlc.hpp:36:10: fatal error: 'iostream' file not found
#include <iostream>
         ^~~~~~~~~~
1 error generated.
In file included from /Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uuu/hotspot/src/share/vm/adlc/filebuff.cpp:26:
/Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uuu/hotspot/src/share/vm/adlc/adlc.hpp:36:10: fatal error: 'iostream' file not foundmake[6]: *** [../generated/adfiles/arena.o] Error 1
make[6]: *** Waiting for unfinished jobs....

#include <iostream>
         ^~~~~~~~~~
In file included from /Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uuu/hotspot/src/share/vm/adlc/dict2.cpp:27:
/Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uuu/hotspot/src/share/vm/adlc/adlc.hpp:36:10: fatal error: 'iostream' file not found
#include <iostream>
         ^~~~~~~~~~
1 error generated.
make[6]: *** [../generated/adfiles/archDesc.o] Error 1
1 error generated.
make[6]: *** [../generated/adfiles/filebuff.o] Error 1
1 error generated.
make[6]: *** [../generated/adfiles/forms.o] Error 1
1 error generated.
1 error generated.
make[6]: *** [../generated/adfiles/dict2.o] Error 1
make[6]: *** [../generated/adfiles/dfa.o] Error 1
1 error generated.
make[6]: *** [../generated/adfiles/adlparse.o] Error 1
make[5]: *** [ad_stuff] Error 2
make[4]: *** [debug] Error 2
make[3]: *** [generic_build2] Error 2
make[2]: *** [debug] Error 2
make[1]: *** [/Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uuu/build/macosx-x86_64-normal-server-slowdebug/hotspot/_hotspot.timestamp] Error 2
make: *** [hotspot-only] Error 2

==============================================================

lizhengdeMacBook-Pro:jdk8uuu lizheng$ export CFLAGS="-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1"
lizhengdeMacBook-Pro:jdk8uuu lizheng$ export CXXFLAGS="-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1"
lizhengdeMacBook-Pro:jdk8uuu lizheng$ export LDFLAGS=-L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/
lizhengdeMacBook-Pro:jdk8uuu lizheng$ export LIBRARY_PATH=$LIBRARY_PATH:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/

==============================================================

lizhengdeMacBook-Pro:jdk8uuu lizheng$ make all JOBS=8 ZIP_DEBUGINFO_FILES=0 COMPILER_WARNINGS_FATAL=false  CC=clang USE_CLANG=true LP64=1
Building OpenJDK for target 'all' in configuration 'macosx-x86_64-normal-server-slowdebug'

## Starting langtools
## Finished langtools (build time 00:00:00)

## Starting hotspot
## Finished docs (build time 00:03:11)

----- Build times -------
Start 2020-04-20 09:32:00
End   2020-04-20 09:49:13
00:00:42 corba
00:01:01 demos
00:03:11 docs
00:03:55 hotspot
00:01:50 images
00:00:22 jaxp
00:00:39 jaxws
00:05:11 jdk
00:00:00 langtools
00:00:22 nashorn
00:17:13 TOTAL
-------------------------
Finished building OpenJDK for target 'all'

配置期异常

1.错误Xcode 4 is required to build JDK 8, the version found was 11.4.

configure: error: Xcode 4 is required to build JDK 8, the version found was 11.4. Use --with-xcode-path to specify the location of Xcode 4 or make Xcode 4 active by using xcode-select.

修改配置文件common/autoconf/generated-configure.sh,去除!

26788     if test ! "${XC_VERSION_PARTS[0]}" = "4"; then
26789       as_fn_error $? "Xcode 4 is required to build JDK 8, the version found was $XCODE_VERSION. Use --with-xcode-path to specify the location of Xcode 4 or make Xcode 4 active by using xcode-select.      " "$LINENO" 5
26790     fi

2.错误# as_fn_error $? "A $TOOLCHAIN_TYPE compiler is required. Try setting --with-tools-dir." "$LINENO" 5参考文章

修改后为
#as_fn_error $? "GCC compiler is required. Try setting --with-tools-dir." "$LINENO" 5

3.错误configure: error: Unable to find objcopy, cannot enable debug-symbols

checking for target address size... 64 bits
checking whether byte ordering is bigendian... no
checking if compiler supports "-m64"... yes
checking if compiler supports "-m64"... yes
checking if we should generate debug symbols... configure: error: Unable to find objcopy, cannot enable debug-symbols
configure exiting with result code 1

安装binutils,并加上OBJCOPY=gobjcopy

参考:https://www.cnblogs.com/jhxxb/p/12558970.html

lizhengdeMacBook-Pro:openjdk8 lizheng$ brew install binutils
==> Downloading https://mirrors.aliyun.com/homebrew/homebrew-bottles/bottles/binutils-2.34.catalina.bottle.tar.gz
######################################################################## 100.0%
==> Pouring binutils-2.34.catalina.bottle.tar.gz
==> Caveats
binutils is keg-only, which means it was not symlinked into /usr/local,
because Apple's CLT provides the same tools.

If you need to have binutils first in your PATH run:
  echo 'export PATH="/usr/local/opt/binutils/bin:$PATH"' >> ~/.bash_profile

For compilers to find binutils you may need to set:
  export LDFLAGS="-L/usr/local/opt/binutils/lib"
  export CPPFLAGS="-I/usr/local/opt/binutils/include"

==> Summary
  /usr/local/Cellar/binutils/2.34: 138 files, 167.3MB

4. 错误ccache status: installed, but disabled (version older than 3.1.4)

Build performance summary:
* Cores to use:   2
* Memory limit:   6144 MB
* ccache status:  installed, but disabled (version older than 3.1.4)

Build performance tip: ccache gives a tremendous speedup for C++ recompilations.
You have ccache installed, but it is a version prior to 3.1.4. Try upgrading.

安装ccache

lizhengdeMacBook-Pro:openjdk8 lizheng$ brew install ccache
lizhengdeMacBook-Pro:openjdk8 lizheng$ ccache --version
ccache version 3.7.9

Copyright (C) 2002-2007 Andrew Tridgell
Copyright (C) 2009-2020 Joel Rosdahl

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 3 of the License, or (at your option) any later
version.

5. 错误configure: error: Xcode 4 is required to build JDK 8, the version found was 11.4. Use --with-xcode-path to specify the location of Xcode 4 or make Xcode 4 active by using xcode-select.

checking for xcodebuild... /usr/bin/xcodebuild
configure: error: Xcode 4 is required to build JDK 8, the version found was 11.4. Use --with-xcode-path to specify the location of Xcode 4 or make Xcode 4 active by using xcode-select.
configure exiting with result code 1

加上–with-xcode-path

configure: Using default toolchain gcc (GNU Compiler Collection)
checking Determining if we need to set DEVELOPER_DIR... configure: error: Xcode Developer path does not exist: yes/Contents/Developer, please provide a path to the Xcode 4 application bundle using --with-xcode-path
configure exiting with result code 1

参考:https://www.jianshu.com/p/03ddf147cb15

26713     if test -n "$XCODE_PATH"; then
26714       DEVELOPER_DIR="$XCODE_PATH"/Contents/Developer
26715     fi
lizhengdeMacBook-Pro:jdk8uu lizheng$ ll /Applications/Xcode.app/Contents/Developer/
total 0
drwxr-xr-x  4 root  wheel  128 Mar 10 09:53 Applications/
drwxr-xr-x  7 root  wheel  224 Mar 10 09:53 Library/
drwxr-xr-x  6 root  wheel  192 Mar 10 09:54 Makefiles/
drwxr-xr-x  9 root  wheel  288 Mar 10 09:41 Platforms/
drwxr-xr-x  3 root  wheel   96 Mar  7 11:15 Toolchains/
drwxr-xr-x  8 root  wheel  256 Apr 15 21:10 Tools/
drwxr-xr-x  6 root  wheel  192 Mar 10 09:51 usr/
lizhengdeMacBook-Pro:jdk8uu lizheng$ export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer/
lizhengdeMacBook-Pro:jdk8uu lizheng$ export XCODE_PATH=/Applications/Xcode.app

编译期异常

1. 第一个必须说的异常,目前还没在网上发现答案adlc.hpp:36:10: fatal error: 'iostream' file not found

clang-10: warning: include path for libstdc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
clang-10: warning: include path for libstdc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
clang-10: warning: include path for libstdc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
Compiling /Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uu/hotspot/src/share/vm/adlc/dict2.cpp
In file included from /Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uu/hotspot/src/share/vm/adlc/archDesc.cpp:27:
/Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uu/hotspot/src/share/vm/adlc/adlc.hpp:36:10: fatal error: 'iostream' file not found
#include <iostream>
         ^~~~~~~~~~
In file included from /Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uu/hotspot/src/share/vm/adlc/adlparse.cpp:27:
/Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uu/hotspot/src/share/vm/adlc/adlc.hpp:36:10: fatal error: 'iostream' file not found
#include <iostream>
         ^~~~~~~~~~
Compiling /Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uu/hotspot/src/share/vm/adlc/filebuff.cpp
clang-10: warning: include path for libstdc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
In file included from /Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uu/hotspot/src/share/vm/adlc/arena.cpp:25:
/Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uu/hotspot/src/share/vm/adlc/adlc.hpp:36:10: fatal error: 'iostream' file not found
#include <iostream>
         ^~~~~~~~~~
Compiling /Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uu/hotspot/src/share/vm/adlc/forms.cpp
clang-10: warning: include path for libstdc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]

这个问题原因是因为Xcode 10以后删除了libstdc++库,转而使用libc++,我做过很多尝试都没办法解决,可以参考这篇文章

=====以下是无效尝试

  1. 第一个就是按报错提示,在编译的时候加上-stdlib=libc++,用这个方法出现一堆日志根本没办法看,而且编译不通过

  2. 使用stackover方法用#include "/Library/Developer/CommandLineTools/usr/include/c++/v1/iostream"替换#include <iostream>,这个会报一个

  3. 下载安装Xcode_9.4.1.xip,安装后Xcode-select --switch切换路径,报错

    promote:jdk8uu lizheng$ sudo xcode-select -s /Applications/Xcode9.4.1/Xcode.app/Contents/Developer/
    Password:
    promote:jdk8uu lizheng$ xcode-select -p
    /Applications/Xcode9.4.1/Xcode.app/Contents/Developer
    promote:jdk8uu lizheng$ make all JOBS=8 ZIP_DEBUGINFO_FILES=0 COMPILER_WARNINGS_FATAL=false  CC=clang USE_CLANG=true LP64=1
    dyld: Symbol not found: _OBJC_IVAR_$_NSFont._fFlags
      Referenced from: /Applications/Xcode9.4.1/Xcode.app/Contents/SharedFrameworks/DVTDocumentation.framework/Versions/A/../../../../SharedFrameworks/DVTKit.framework/Versions/A/DVTKit
      Expected in: /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit
     in /Applications/Xcode9.4.1/Xcode.app/Contents/SharedFrameworks/DVTDocumentation.framework/Versions/A/../../../../SharedFrameworks/DVTKit.framework/Versions/A/DVTKit
    make: error: unable to locate xcodebuild, please make sure the path to the Xcode folder is set correctly!
    make: error: You can set the path to the Xcode folder using /usr/bin/xcode-select -switch
    

=======以下是成功方法=

最后使用的办法是从github上下载库,然后设置环境变量后解决,此方法我编译过两次都通过

  1. git clone https://github.com/imkiwa/xcode-missing-libstdc-.git

  2. 执行install.sh,脚本如下

    #!/usr/bin/env bash
    
    set -e
    
    sudo ln -s \
        $PWD/include/c++ \
        /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/
    
    sudo ln -s \
        $PWD/lib/libstdc++.6.0.9.tbd \
        $PWD/lib/libstdc++.6.tbd \
        $PWD/lib/libstdc++.tbd \
        /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/
    
  3. 做完以上两步还是报同样的错,需要设置环境变量,可以参考这篇文章

    export CFLAGS="-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1"
    export CXXFLAGS="-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1"
    export LDFLAGS=-L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/
    
  4. 完成以上设置还会报错ld: library not found for -lstdc++,可以参考这篇文章,解决办法如下:

    export LIBRARY_PATH=$LIBRARY_PATH:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/
    
    

2. 报错error: invalid argument '-std=gnu++98' not allowed with 'C' make[6]: *** [libjsig.dylib] Error 1,解决办法参考https://www.cnblogs.com/zhengshuangxi/p/11063938.html

3.错误error: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wreserved-user-defined-literal],这是一类错误,有很多文件都需要修改,修改方法就是加空格,参考这篇文章

In file included from <built-in>:1:
In file included from /Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uu/hotspot/src/share/vm/precompiled/precompiled.hpp:306:
/Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uu/hotspot/src/share/vm/gc_implementation/g1/g1BlockOffsetTable.inline.hpp:52:32: error: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wreserved-user-defined-literal]
         err_msg("%s - index: "SIZE_FORMAT", _vs.committed_size: "SIZE_FORMAT, \
                               ^
                                
/Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uu/hotspot/src/share/vm/gc_implementation/g1/g1BlockOffsetTable.inline.hpp:52:67: error: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wreserved-user-defined-literal]
         err_msg("%s - index: "SIZE_FORMAT", _vs.committed_size: "SIZE_FORMAT, \
                                                                  ^
                                                                   
/Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uu/hotspot/src/share/vm/gc_implementation/g1/g1BlockOffsetTable.inline.hpp:55:26: error: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wreserved-user-defined-literal]
         err_msg("Index "SIZE_FORMAT" corresponding to "PTR_FORMAT             \
                         ^
                          
/Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uu/hotspot/src/share/vm/gc_implementation/g1/g1BlockOffsetTable.inline.hpp:55:57: error: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wreserved-user-defined-literal]
         err_msg("Index "SIZE_FORMAT" corresponding to "PTR_FORMAT             \
                                                        ^
                                                         
2 warnings and 6 errors generated.
make[6]: *** [precompiled.hpp.pch] Error 1



/Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uu/hotspot/src/share/vm/memory/generation.hpp:426:30: error: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wreserved-user-defined-literal]
        warning("time warp: "INT64_FORMAT" to "INT64_FORMAT, (int64_t)_time_of_last_gc, (int64_t)now);
                             ^
                              
/Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uu/hotspot/src/share/vm/memory/generation.hpp:426:48: error: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wreserved-user-defined-literal]
        warning("time warp: "INT64_FORMAT" to "INT64_FORMAT, (int64_t)_time_of_last_gc, (int64_t)now);

4. 错误error: comparison between pointer and integer ('address' (aka 'unsigned char *') and 'bool')

warning: include path for libstdc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
/Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uu/hotspot/src/share/vm/code/compiledIC.cpp:225:15: error: comparison between pointer and integer ('address' (aka 'unsigned char *') and 'bool')
    if (entry == false) {
    
        ~~~~~ ^  ~~~~~~~~~~~
1 error generated.
make[6]: *** [compiledIC.o] Error 1

修改代码compiledIC.cpp:225:15:
if ((bool)entry == false) {
    

5.错误error: case value evaluates to 3758096385, which cannot be narrowed to type 'int' [-Wc++11-narrowing]

/Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uu/hotspot/src/share/vm/utilities/vmError.cpp:398:13: error: case value evaluates to 3758096385, which cannot be narrowed to type 'int' [-Wc++11-narrowing]
       case OOM_MALLOC_ERROR:
            ^
/Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uu/hotspot/src/share/vm/utilities/vmError.cpp:399:13: error: case value evaluates to 3758096386, which cannot be narrowed to type 'int' [-Wc++11-narrowing]
       case OOM_MMAP_ERROR:
            ^
/Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uu/hotspot/src/share/vm/utilities/vmError.cpp:424:13: error: case value evaluates to 3758096384, which cannot be narrowed to type 'int' [-Wc++11-narrowing]
       case INTERNAL_ERROR:

修改代码

 397     switch((long)_id) {
     
 398        case OOM_MALLOC_ERROR:
 399        case OOM_MMAP_ERROR:
 400          if (_size) {
     
 401            st->print("# Native memory allocation ");
 402            st->print((_id == (int)OOM_MALLOC_ERROR) ? "(malloc) failed to allocate " :
 403                                                  "(mmap) failed to map ");
 404            jio_snprintf(buf, sizeof(buf), SIZE_FORMAT, _size);
 405            st->print("%s", buf);
 406            st->print(" bytes");
 407            if (_message != NULL) {
     
 408              st->print(" for ");
 409              st->print("%s", _message);
 410            }
 411            st->cr();
 412          } else {
     
 413            if (_message != NULL)
 414              st->print("# ");
 415              st->print_cr("%s", _message);
 416          }
 417          // In error file give some solutions
 418          if (_verbose) {
     
 419            print_oom_reasons(st);
 420          } else {
     
 421            return;  // that's enough for the screen
 422          }
 423          break;
 424        case INTERNAL_ERROR:
 425        default:
 426          break;
 427      }

6. 错误error: cannot initialize return object of type 'jobject' (aka '_jobject *') with an rvalue of type 'bool'

/Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uu/jdk/src/share/native/com/sun/java/util/jar/pack/jni.cpp:295:12: error: cannot initialize return object of type 'jobject' (aka '_jobject *') with an rvalue of type 'bool'
    return false;
           ^~~~~
1 error generated.

修改代码:

293   if (uPtr->aborting()) {
    
294     THROW_IOE(uPtr->get_abort_message());
295     return 0;
296   }

7.错误Undefined symbols for architecture x86_64,参考修改方法

Undefined symbols for architecture x86_64:
  "_attachCurrentThread", referenced from:
      +[ThreadUtilities getJNIEnv] in ThreadUtilities.o
      +[ThreadUtilities getJNIEnvUncached] in ThreadUtilities.o
ld: symbol(s) not found for architecture x86_64
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [/Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uu/build/macosx-x86_64-normal-server-slowdebug/jdk/lib/libosxapp.dylib] Error 1
make[2]: *** Waiting for unfinished jobs....
2 warnings generated.
2 warnings generated.
In file included from /Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uu/jdk/src/macosx/native/com/apple/laf/ScreenMenu.m:26:
In file included from /Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uu/jdk/src/macosx/native/com/apple/laf/ScreenMenu.h:28:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/JavaVM.framework/Frameworks/JavaNativeFoundation.framework/Headers/JavaNativeFoundation.h:11:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/JavaVM.framework/Frameworks/JavaNativeFoundation.framework/Headers/JNFJNI.h:30:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/JavaVM.framework/Frameworks/JavaNativeFoundation.framework/Headers/JNFException.h:49:1: warning: method has no return type specified; defaults to 'id' [-Wmissing-method-return-type]
- init:(JNIEnv *)env throwable:(jthrowable)throwable;
^
  (id)
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/JavaVM.framework/Frameworks/JavaNativeFoundation.framework/Headers/JNFException.h:50:1: warning: method has no return type specified; defaults to 'id' [-Wmissing-method-return-type]
- init:(JNIEnv *)env as:(const char *)javaExceptionType reason:(const char *)reasonMsg;
^
  (id)
2 warnings generated.
make[1]: *** [libs-only] Error 2
make: *** [jdk-only] Error 2
​```
修改 **jdk/src/macosx/native/sun/osxapp/ThreadUtilities.m ** 文件的38行
将
	inline void attachCurrentThread(void** env) {
      
修改为:
	static inline void attachCurrentThread(void** env) {
      ```

8.运行时错误[libjvm.dylib+0xa35b18] PerfData::~PerfData()+0x8

promote:bin lizheng$ ./java -version
openjdk version "1.8.0-internal-debug"
OpenJDK Runtime Environment (build 1.8.0-internal-debug-lizheng_2020_04_19_22_06-b00)
OpenJDK 64-Bit Server VM (build 25.71-b00-debug, mixed mode)
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGILL (0x4) at pc=0x0000000108835b18, pid=2960, tid=0x0000000000002303
#
# JRE version: OpenJDK Runtime Environment (8.0) (build 1.8.0-internal-debug-lizheng_2020_04_19_22_06-b00)
# Java VM: OpenJDK 64-Bit Server VM (25.71-b00-debug mixed mode bsd-amd64 compressed oops)
# Problematic frame:
# V  [libjvm.dylib+0xa35b18]  PerfData::~PerfData()+0x8
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /Users/lizheng/Documents/3-data/5-source/java/javase/jdk8uu/build/macosx-x86_64-normal-server-slowdebug/images/j2sdk-image/bin/hs_err_pid2960.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
#

[error occurred during error reporting , id 0x4]

Abort trap: 6

查看日志中的栈调用信息

Stack: [0x0000700009987000,0x0000700009a87000],  sp=0x0000700009a86d70,  free space=1023k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.dylib+0xa35b18]  PerfData::~PerfData()+0x8
V  [libjvm.dylib+0xa3681d]  PerfDataManager::destroy()+0x6d
V  [libjvm.dylib+0xa38edd]  perfMemory_exit()+0x3d
V  [libjvm.dylib+0x67163d]  exit_globals()+0x1d
V  [libjvm.dylib+0xb85eb9]  Threads::destroy_vm()+0x199
V  [libjvm.dylib+0x73f175]  jni_DestroyJavaVM+0x175
C  [java+0x40cc]  JavaMain+0x27c
C  [libsystem_pthread.dylib+0x6109]  _pthread_start+0x94
C  [libsystem_pthread.dylib+0x1b8b]  thread_start+0xf

参考网上文章文章2:注释hotspot/src/share/vm/runtime/perfMemory.cpp,注意可能会导致 内存泄露

hotspot/src/share/vm/runtime/perfMemory.cpp

 73   //if (!StatSampler::is_active())
 74   //  PerfDataManager::destroy();
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/lizhengjava/article/details/105629780

智能推荐

我学cocos2d-x (三) Node:一切可视化对象的祖先_cococs cocos2d::node 使用-程序员宅基地

文章浏览阅读1k次。在cocos2d-x中一切可视化的元素都集成自Node,zhe's_cococs cocos2d::node 使用

20180806 考试记录-程序员宅基地

文章浏览阅读74次。20180806 考试记录 T1 【NOIP2013模拟联考8】最短路(path)Solution设s为第0个标记点,t为k+1个跑k+1次最短路然后全排列暴力求解qwq注意最大值要设为long long范围最大值CodePS:各种修改qwq//By Menteur_Hxy#include&lt;queue&gt;#include..._i <= 3000000000u

DBA整理的万字详解MySQL性能优化,值得收藏!-程序员宅基地

文章浏览阅读190次。点击关注公众号,实用技术文章及时了解作者:LanceToBigDatacnblogs.com/zhangyinhua/p/7620964.html说起MySQL的查询优化,相信大家积累...

云开发(3)云函数本地调试_本地云函数调试并发数量限制-程序员宅基地

文章浏览阅读921次。云函数/云函数本地调试云函数是云开发其中一项基础能力,在云端运行的代码,微信私有协议天然鉴权,开发者只需编写自身业务逻辑代码。云函数个数免费版云函数数量上限为 50写完自己的原函数后,可以通过云函数的本地调试来进行调试,调试没有问题了就可以上传云端,对于解决bug查找bug是很好用的使用像调试自己的哪一个云函数就直接右键开启本地调试即可。就是这样一个页面此时运行自己的云函数就是在本地运行不是再云端给运行了。可以调试没问题后再传到云端,有时候会弹出一个错误解决方法:右键点击你_本地云函数调试并发数量限制

SQL创建默认值语句(CREATE DEFAULT)-程序员宅基地

文章浏览阅读5.8k次。微软的解释:创建称为默认值的对象。当绑定到列或别名数据类型时,如果插入时没有显式提供值,则默认值将指定一个值,以便将其插入该对象所绑定的列中(或者,如果是别名数据类型,则插入所有列中)。后续版本的 Microsoft SQL Server 将删除该功能。请避免在新的开发工作中使用该功能,并着手修改当前还在使用该功能的应用程序。语法 ..._sql declare default

Linux分区格式化实训操作说明_sdb7这个分区的具体含义-程序员宅基地

文章浏览阅读2.2k次。首先介绍一下背景知识:Linux主分区,扩展分区,逻辑分区的联系和区别Linux硬盘分区有三种,主磁盘分区、扩展磁盘分区、逻辑分区。一个硬盘主分区至少有1个,最多4个,扩展分区可以没有,最多1个。且主分区+扩展分区总共不能超过4个。逻辑分区可以有若干个。在linux下主分区和逻辑分区都可以用来放系统,引导os开机。分出主分区后,其余的部分可以分成扩展分区,一般情况是剩余磁盘空间全部配成扩展分区,..._sdb7这个分区的具体含义

随便推点

oracle9i打补丁,oracle11gr2打PSU补丁记录-程序员宅基地

文章浏览阅读72次。1、将数据库和监听程序关闭2、首先检查OPatch版本是否符合要求:$ORACLE_HOME/OPatch/opatch lsinventory3、若不符合要求,需先更新opatch:mv 掉原有的OPatch目录mv $ORACLE_HOME/OPatch $ORACLE_HOME/OPatchbakcp p6880880_112000_SOLARIS64-opatch11.2.0.3.12.z..._oracle9i 打补丁时ouihome设置

java ocr技术--tesseract-ocr:使用jTessBoxEditor制作训练库_jtessboxeditor训练英文和数字结合的图片-程序员宅基地

文章浏览阅读1.8k次,点赞4次,收藏18次。几个常见的问题:问题一:相关的几个软件下载地址Tesseract:Index of /tesseractjTessBoxEditor: VietOCR - Browse /jTessBoxEditor at SourceForge.net问题二:jTessBoxEditor下载是注意一下,中文的话要下载jTessBoxEditorFX问题三:mftraining执行时提示停止工作,一般是Tesseract版本的问题,可以选择Tesseract3验证过是好的,Tesser._jtessboxeditor训练英文和数字结合的图片

天平称重,进制转换解法_天平称重(进制解法) python-程序员宅基地

文章浏览阅读302次。题目:用天平称重时,我们希望用尽可能少的砝码组合称出尽可能多的重量。如果只有5个砝码,重量分别是1,3,9,27,81则它们可以组合称出1到121之间任意整数重量(砝码允许放在左右两个盘中)。本题目要求编程实现:对用户给定的重量,给出砝码组合方案。例如:用户输入:5程序输出:9-3-1用户输入:19程序输出:27-9+1要求程序输出的组合总是大数在前小数在后。可以假设用户的输入的数字符合范围1~121。思路:观察输出,都是3的多少次方,所以我们可以把输入的值,转换成3进制的_天平称重(进制解法) python

druid-1.1.21.jar-程序员宅基地

文章浏览阅读954次。链接:https://pan.baidu.com/s/1w5_GTiWuAR_X2t8J7JIP4Q提取码:a0u1_druid-1.1.21.jar

pthread_spinlock_t与pthread_mutex_t性能对比_pthread 性能 效率-程序员宅基地

文章浏览阅读8k次。看到一篇pthread_spinlock_t与pthread_mutex_t性能对比做的非常细致的博客,记录下来原文在此:http://www.cnblogs.com/diyunpeng/archive/2011/06/07/2074059.html_pthread 性能 效率

mysql innodb与myisam存储文件的区别-程序员宅基地

文章浏览阅读1.1k次。myisam:.frm: 存储表定义.myd(MYData):存储数据.MYI(MYindex):存储引擎innodb:.frm:存储表定义.idb:存储数据和索引,在同一个文件中_innodb和mylsam生成文件的区别