• cmake利用toolchain.cmake生成makefile之后,make生成静态库失败问题


    问题描述

    利用toolchian.cmake设置好编译器后,利用make指令生成静态库,出现以下问题

     Error running link command: No such file or directory

    出错原因,toolchain.cmake文件内没有声明静态库生成器AR;解决方式,在toolchian.cmake文件内添加下面的声明

    SET(CMAKE_AR  $(TOOLCHAIN_DIR)/bin/arm-linux-gnueabihf-ar CACHE FILEPATH "Archiver")

    我之前的设置是

    SET(CMAKE_AR  $(TOOLCHAIN_DIR)/bin/arm-linux-gnueabihf-ar)

    仍然会报错,在查看了cmake 的文档后发现

    Set Normal Variable
    set(<variable> <value>... [PARENT_SCOPE])
    Set the given <variable> in the current function or directory scope.
    
    If the PARENT_SCOPE option is given the variable will be set in the scope above the current scope. Each new directory or function creates a new scope. This command will
    set the value of a variable into the parent directory or calling function (whichever is applicable to the case at hand). The previous state of the variable’s value stays
    the same in the current scope (e.g., if it was undefined before, it is still undefined and if it had a value, it is still that value).

    Cache 变量

    Set Cache Entry
    set(<variable> <value>... CACHE <type> <docstring> [FORCE])
    Set the given cache <variable> (cache entry). Since cache entries are meant to provide user-settable values this does not overwrite existing cache entries by default. 
    Use the FORCE option to overwrite existing entries. The
    <type> must be specified as one of: BOOL Boolean ON/OFF value. cmake-gui(1) offers a checkbox. FILEPATH Path to a file on disk. cmake-gui(1) offers a file dialog. PATH Path to a directory on disk. cmake-gui(1) offers a file dialog. STRING A line of text. cmake-gui(1) offers a text field or a drop-down selection if the STRINGS cache entry property is set. INTERNAL A line of text. cmake-gui(1) does not show internal entries. They may be used to store variables persistently across runs. Use of this type implies FORCE. The <docstring> must be specified as a line of text providing a quick summary of the option for presentation to cmake-gui(1) users. If the cache entry does not exist prior to the call or the FORCE option is given then the cache entry will be set to the given value. Furthermore, any normal variable
    binding in the current scope will be removed to expose the newly cached value to any immediately following evaluation. It is possible for the cache entry to exist prior to the call but have no type set if it was created on the cmake(1) command line by a user through the -D<var>=<value>
    option without specifying a type. In this case the set command will add the type. Furthermore, if the <type> is PATH or FILEPATH and the <value> provided on the command
    line is a relative path, then the set command will treat the path as relative to the current working directory and convert it to an absolute path.

    之后删除build文件下的所有内容

    rm -rf *

    再次调用cmake生成makefile

    cmake -DCMAKE_TOOLCHAIN_FILE=~/toolchain.cmake ../

    编译即可

    make VERBOSE=1 -j5
  • 相关阅读:
    PHP基础知识系列:预定义变量
    PHP基础知识系列:拦截器方法
    【PHP设计模式】创建型之单例(Singleton)
    PHP基础知识系列:cookie与session
    select问题
    柳传志给杨元庆的信
    PHP基础知识系列:多态性
    PHP基础知识系列:面向对象基础
    PHP处理字符串翻转问题总结
    PHP基础知识系列:静态
  • 原文地址:https://www.cnblogs.com/flyinggod/p/8042705.html
Copyright © 2020-2023  润新知