前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >macOS:编译boost静态库 error:implicit declaration of function ‘out_printf‘ is invalid in C99

macOS:编译boost静态库 error:implicit declaration of function ‘out_printf‘ is invalid in C99

作者头像
10km
发布2021-04-19 16:14:55
1.8K1
发布2021-04-19 16:14:55
举报
文章被收录于专栏:10km的专栏10km的专栏

macOS下如果你使用brew安装boost,很方便

brew install boost

但默认安装出来的boost 1.75是动态库,如果想要静态库版本还是要自己编译。

于是我到boost官网下载了boost 1.62

在执行./bootstrap.sh失败了。 查看./bootstrap.log,如下:

###
### Using 'darwin' toolset.
###
rm -rf bootstrap
mkdir bootstrap
cc -o bootstrap/jam0 command.c compile.c constants.c debug.c execcmd.c frames.c function.c glob.c hash.c hdrmacro.c headers.c jam.c jambase.c jamgram.c lists.c make.c make1.c object.c option.c output.c parse.c pathsys.c regexp.c rules.c scan.c search.c subst.c timestamp.c variable.c modules.c strings.c filesys.c builtins.c class.c cwd.c native.c md5.c w32_getreg.c modules/set.c modules/path.c modules/regex.c modules/property-set.c modules/sequence.c modules/order.c execunix.c fileunix.c pathunix.c
execcmd.c:120:5: error: implicit declaration of function 'out_printf' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    out_printf( "...interrupted\n" );
    ^
1 error generated.
make.c:132:13: error: implicit declaration of function 'out_printf' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
            out_printf( "...found %d target%s...\n", counts->targets,
            ^
make.c:184:17: error: implicit declaration of function 'out_printf' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
                out_printf( "fate change  %s from %s to %s (as dependant of %s)\n",
                ^
make.c:215:17: error: implicit declaration of function 'out_printf' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
                out_printf( "fate change  %s from %s to %s (by rebuild)\n",
                ^
make.c:300:9: error: implicit declaration of function 'out_printf' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        out_printf( "make\t--\t%s%s\n", spaces( depth ), object_str( t->name ) );
        ^
make.c:300:41: warning: adding 'int' to a string does not append to the string [-Wstring-plus-int]
        out_printf( "make\t--\t%s%s\n", spaces( depth ), object_str( t->name ) );
                                        ^~~~~~~~~~~~~~~
make.c:85:44: note: expanded from macro 'spaces'
#define spaces(x) ( "                    " + ( x > 20 ? 0 : 20-x ) )
                    ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
make.c:300:41: note: use array indexing to silence this warning
make.c:85:44: note: expanded from macro 'spaces'
#define spaces(x) ( "                    " + ( x > 20 ? 0 : 20-x ) )
                                           ^
make.c:307:41: warning: adding 'int' to a string does not append to the string [-Wstring-plus-int]
        out_printf( "make\t--\t%s%s\n", spaces( depth ), object_str( t->name ) );
                                        ^~~~~~~~~~~~~~~
make.c:85:44: note: expanded from macro 'spaces'
#define spaces(x) ( "                    " + ( x > 20 ? 0 : 20-x ) )
                    ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
make.c:307:41: note: use array indexing to silence this warning
make.c:85:44: note: expanded from macro 'spaces'
#define spaces(x) ( "                    " + ( x > 20 ? 0 : 20-x ) )
                                           ^
make.c:380:49: warning: adding 'int' to a string does not append to the string [-Wstring-plus-int]
            out_printf( "bind\t--\t%s%s: %s\n", spaces( depth ),
                                                ^~~~~~~~~~~~~~~
make.c:85:44: note: expanded from macro 'spaces'
#define spaces(x) ( "                    " + ( x > 20 ? 0 : 20-x ) )
                    ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
make.c:380:49: note: use array indexing to silence this warning
make.c:85:44: note: expanded from macro 'spaces'
#define spaces(x) ( "                    " + ( x > 20 ? 0 : 20-x ) )
                                           ^
make.c:388:49: warning: adding 'int' to a string does not append to the string [-Wstring-plus-int]
            out_printf( "time\t--\t%s%s: %s\n", spaces( depth ),
                                                ^~~~~~~~~~~~~~~
make.c:85:44: note: expanded from macro 'spaces'
#define spaces(x) ( "                    " + ( x > 20 ? 0 : 20-x ) )
                    ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
make.c:388:49: note: use array indexing to silence this warning
make.c:85:44: note: expanded from macro 'spaces'
#define spaces(x) ( "                    " + ( x > 20 ? 0 : 20-x ) )
                                           ^
make.c:393:49: warning: adding 'int' to a string does not append to the string [-Wstring-plus-int]
            out_printf( "time\t--\t%s%s: %s\n", spaces( depth ),
                                                ^~~~~~~~~~~~~~~
make.c:85:44: note: expanded from macro 'spaces'
#define spaces(x) ( "                    " + ( x > 20 ? 0 : 20-x ) )
                    ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
make.c:393:49: note: use array indexing to silence this warning
make.c:85:44: note: expanded from macro 'spaces'
#define spaces(x) ( "                    " + ( x > 20 ? 0 : 20-x ) )
                                           ^
make.c:735:13: error: implicit declaration of function 'out_flush' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
            out_flush();
            ^
make.c:758:13: warning: adding 'int' to a string does not append to the string [-Wstring-plus-int]
            spaces( depth ), object_str( t->name ) );
            ^~~~~~~~~~~~~~~
make.c:85:44: note: expanded from macro 'spaces'
#define spaces(x) ( "                    " + ( x > 20 ? 0 : 20-x ) )
                    ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
make.c:758:13: note: use array indexing to silence this warning
make.c:85:44: note: expanded from macro 'spaces'
#define spaces(x) ( "                    " + ( x > 20 ? 0 : 20-x ) )
                                           ^
6 warnings and 5 errors generated.
filesys.c:360:10: error: implicit declaration of function 'filelist_empty' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    if ( filelist_empty( archive->members ) )
         ^
filesys.c:496:10: error: implicit declaration of function 'filelist_empty' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    if ( filelist_empty( list ) )
         ^
filesys.c:534:10: error: implicit declaration of function 'filelist_empty' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    if ( filelist_empty( list ) )
         ^
filesys.c:570:10: error: implicit declaration of function 'filelist_empty' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    if ( filelist_empty( list ) ) return list;
         ^
filesys.c:593:11: error: implicit declaration of function 'filelist_empty' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    if ( !filelist_empty( list ) ) result = list->size;
          ^
filesys.c:602:10: error: implicit declaration of function 'filelist_empty' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    if ( filelist_empty( list ) ) return;
         ^
6 errors generated.
modules/path.c:16:12: error: implicit declaration of function 'file_query' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    return file_query( list_front( lol_get( frame->args, 0 ) ) ) ?
           ^
1 error generated.
fileunix.c:233:10: error: implicit declaration of function 'filelist_empty' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    if ( filelist_empty( archive->members ) )
         ^
fileunix.c:235:14: error: implicit declaration of function 'file_collect_archive_content_' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        if ( file_collect_archive_content_( archive ) < 0 )
             ^
fileunix.c:235:14: note: did you mean 'file_collect_dir_content_'?
fileunix.c:110:5: note: 'file_collect_dir_content_' declared here
int file_collect_dir_content_( file_info_t * const d )
    ^
fileunix.c:294:12: error: implicit declaration of function 'filelist_empty' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    if ( ! filelist_empty( archive->members ) ) filelist_free( archive->members );
           ^
3 errors generated.

按照这篇文章的说明

《boost-1.61.0 failure to bootstrap with xcode-12 due to implicit function declarations》

应该是高版本的AppleClang编译器的带来的问题

Clang now reports an error when you use a function without an explicit declaration when building C or Objective-C code for macOS (-Werror=implicit-function-declaration flag is on). This additional error detection unifies Clang’s behavior for iOS/tvOS and macOS 64-bit targets for this diagnostic. (49917738)

1.62.0版本确实比较老了,那么我升级boost该可以解决问题吧?于是我下载了最新的 boost 1.75.0版本

https://dl.bintray.com/boostorg/release/1.75.0/source/boost_1_75_0.tar.gz

再次执行成功了

./bootstrap.sh
## 编译并安装到$install_path指定的位置
./b2 cxxflags=-fPIC cflags=-fPIC --prefix=$install_path -q --debug-configuration link=static install

查看安装的路径,生成全部是 .a 静态库文件

ls -l $install_path/lib total 38976 drwxr-xr-x 41 guyadong staff 1312 4 15 15:02 ./ drwxr-xr-x 4 guyadong staff 128 4 15 15:02 …/ drwxr-xr-x 50 guyadong staff 1600 4 15 15:02 cmake/ -rw-r–r-- 1 guyadong staff 42688 4 15 15:02 libboost_atomic.a -rw-r–r-- 1 guyadong staff 70256 4 15 15:02 libboost_chrono.a -rw-r–r-- 1 guyadong staff 114240 4 15 15:02 libboost_container.a -rw-r–r-- 1 guyadong staff 39024 4 15 15:02 libboost_context.a -rw-r–r-- 1 guyadong staff 137016 4 15 15:02 libboost_contract.a -rw-r–r-- 1 guyadong staff 45952 4 15 15:02 libboost_coroutine.a -rw-r–r-- 1 guyadong staff 912 4 15 15:02 libboost_date_time.a -rw-r–r-- 1 guyadong staff 1008 4 15 15:02 libboost_exception.a -rw-r–r-- 1 guyadong staff 193584 4 15 15:02 libboost_filesystem.a -rw-r–r-- 1 guyadong staff 603216 4 15 15:02 libboost_graph.a -rw-r–r-- 1 guyadong staff 135120 4 15 15:02 libboost_iostreams.a -rw-r–r-- 1 guyadong staff 1067248 4 15 15:01 libboost_locale.a -rw-r–r-- 1 guyadong staff 1937032 4 15 15:01 libboost_log.a -rw-r–r-- 1 guyadong staff 2120192 4 15 15:01 libboost_log_setup.a -rw-r–r-- 1 guyadong staff 225464 4 15 15:01 libboost_math_c99.a -rw-r–r-- 1 guyadong staff 135632 4 15 15:01 libboost_math_c99f.a -rw-r–r-- 1 guyadong staff 172696 4 15 15:01 libboost_math_c99l.a -rw-r–r-- 1 guyadong staff 1115784 4 15 15:01 libboost_math_tr1.a -rw-r–r-- 1 guyadong staff 893792 4 15 15:02 libboost_math_tr1f.a -rw-r–r-- 1 guyadong staff 1058784 4 15 15:02 libboost_math_tr1l.a -rw-r–r-- 1 guyadong staff 65768 4 15 15:02 libboost_numpy27.a -rw-r–r-- 1 guyadong staff 86832 4 15 15:02 libboost_prg_exec_monitor.a -rw-r–r-- 1 guyadong staff 668504 4 15 15:02 libboost_program_options.a -rw-r–r-- 1 guyadong staff 455088 4 15 15:02 libboost_python27.a -rw-r–r-- 1 guyadong staff 24320 4 15 15:02 libboost_random.a -rw-r–r-- 1 guyadong staff 1074400 4 15 15:02 libboost_regex.a -rw-r–r-- 1 guyadong staff 687536 4 15 15:02 libboost_serialization.a -rw-r–r-- 1 guyadong staff 13312 4 15 15:02 libboost_stacktrace_addr2line.a -rw-r–r-- 1 guyadong staff 7464 4 15 15:02 libboost_stacktrace_basic.a -rw-r–r-- 1 guyadong staff 2456 4 15 15:02 libboost_stacktrace_noop.a -rw-r–r-- 1 guyadong staff 880 4 15 15:01 libboost_system.a -rw-r–r-- 1 guyadong staff 1438584 4 15 15:02 libboost_test_exec_monitor.a -rw-r–r-- 1 guyadong staff 121784 4 15 15:02 libboost_thread.a -rw-r–r-- 1 guyadong staff 29880 4 15 15:02 libboost_timer.a -rw-r–r-- 1 guyadong staff 53280 4 15 15:02 libboost_type_erasure.a -rw-r–r-- 1 guyadong staff 1426984 4 15 15:02 libboost_unit_test_framework.a -rw-r–r-- 1 guyadong staff 3149560 4 15 15:02 libboost_wave.a -rw-r–r-- 1 guyadong staff 447832 4 15 15:02 libboost_wserialization.a

使用的编译器为XCode内置的gcc编译器(Apple clang)

$ g++ -v Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1 Apple clang version 12.0.0 (clang-1200.0.32.29) Target: x86_64-apple-darwin20.3.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-04-15 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档