<legend id='2AOYb'><style id='2AOYb'><dir id='2AOYb'><q id='2AOYb'></q></dir></style></legend>
  • <tfoot id='2AOYb'></tfoot>

    <small id='2AOYb'></small><noframes id='2AOYb'>

    <i id='2AOYb'><tr id='2AOYb'><dt id='2AOYb'><q id='2AOYb'><span id='2AOYb'><b id='2AOYb'><form id='2AOYb'><ins id='2AOYb'></ins><ul id='2AOYb'></ul><sub id='2AOYb'></sub></form><legend id='2AOYb'></legend><bdo id='2AOYb'><pre id='2AOYb'><center id='2AOYb'></center></pre></bdo></b><th id='2AOYb'></th></span></q></dt></tr></i><div id='2AOYb'><tfoot id='2AOYb'></tfoot><dl id='2AOYb'><fieldset id='2AOYb'></fieldset></dl></div>

      • <bdo id='2AOYb'></bdo><ul id='2AOYb'></ul>
      1. 在 CMakeLists.txt 中链接 GSL

        Linking GSL in CMakeLists.txt(在 CMakeLists.txt 中链接 GSL)

        <tfoot id='ADzbJ'></tfoot>

        <small id='ADzbJ'></small><noframes id='ADzbJ'>

            <i id='ADzbJ'><tr id='ADzbJ'><dt id='ADzbJ'><q id='ADzbJ'><span id='ADzbJ'><b id='ADzbJ'><form id='ADzbJ'><ins id='ADzbJ'></ins><ul id='ADzbJ'></ul><sub id='ADzbJ'></sub></form><legend id='ADzbJ'></legend><bdo id='ADzbJ'><pre id='ADzbJ'><center id='ADzbJ'></center></pre></bdo></b><th id='ADzbJ'></th></span></q></dt></tr></i><div id='ADzbJ'><tfoot id='ADzbJ'></tfoot><dl id='ADzbJ'><fieldset id='ADzbJ'></fieldset></dl></div>
                <tbody id='ADzbJ'></tbody>
                <bdo id='ADzbJ'></bdo><ul id='ADzbJ'></ul>
              • <legend id='ADzbJ'><style id='ADzbJ'><dir id='ADzbJ'><q id='ADzbJ'></q></dir></style></legend>
                  本文介绍了在 CMakeLists.txt 中链接 GSL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个包含多个文件的代码,它使用 GSL 库.当我使用命令通过终端编译代码时

                  I have a code with multiple files, that uses the GSL Library. When I compile the code through the terminal with the command

                  g++ main.cpp -lm -lgsl -lgslcblas -o Exec
                  

                  这会编译并给出正确的输出并且没有错误.但是,当我尝试在 CLion 中构建代码时,出现错误

                  This compiles and gives the correct output and no errors. However, when I try and build the code in CLion I get the error

                  undefined reference to `gsl_rng_uniform'
                  

                  我已经通过 CMakeLists.txt 链接了代码中的各种 .cpp 文件,但我认为,我必须使用类似于标志的内容才能链接到 GSL.我的 CMakeLists.txt 文件目前如下(源文件中只包含 .cpp 文件,而不包含 .h 文件):

                  I have linked the various .cpp files in my code through the CMakeLists.txt, but I think, I have to something similar to the flags to link to GSL. My CMakeLists.txt file is as follows currently (only the .cpp files are included in the source files, not the .h files):

                  cmake_minimum_required(VERSION 3.7)
                  project(Unitsv1)
                  
                  set(CMAKE_CXX_STANDARD 11)
                  
                  set(SOURCE_FILES main.cpp
                                   transition.cpp
                                   random.cpp)
                  add_executable(Unitsv1 ${SOURCE_FILES})
                  

                  我对 C++ 很陌生,似乎在网上找不到任何答案.谢谢

                  I'm very new to C++, and can't seem to find any answers online. Thanks

                  推荐答案

                  您尚未在 GSL 库中进行链接,因此链接器将找不到它提供的任何符号.像这样的事情应该可以让你大部分时间:

                  You haven't linked in the GSL libraries, so the linker won't find any of the symbols it provides. Something like this should get you most of the way there:

                  cmake_minimum_required(VERSION 3.7)
                  project(Unitsv1)
                  
                  set(CMAKE_CXX_STANDARD 11)
                  set(CMAKE_CXX_STANDARD_REQUIRED YES)   # See below (1)
                  
                  set(SOURCE_FILES main.cpp
                                   transition.cpp
                                   random.cpp)
                  add_executable(Unitsv1 ${SOURCE_FILES})
                  
                  find_package(GSL REQUIRED)    # See below (2)
                  target_link_libraries(Unitsv1 GSL::gsl GSL::gslcblas)
                  

                  如果您的代码使用 C++11,那么您需要 (1) 处的行以确保您真正获得 C++11 支持.如果没有 CMAKE_CXX_STANDARD_REQUIRED YESCMAKE_CXX_STANDARD 变量仅用作如果可用,则使用它,或者回退到编译器可以提供的最接近的标准".如果您愿意,您可以在此处找到详细的文章很好奇.

                  If your code uses C++11, then you need the line at (1) to ensure you actually get C++11 support. Without CMAKE_CXX_STANDARD_REQUIRED YES, the CMAKE_CXX_STANDARD variable acts only as "Use it if it is available, or fall back to the closest standard the compiler can provide". You can find a detailed write-up here if you're curious.

                  您的问题更重要的部分是 (2).find_package() 命令查找 GSL 库等,并将它们用作导入目标 GSL::gslGSL::gslcblas.然后使用 target_link_libraries() 将可执行文件链接到它们,如图所示.CMake 文档详细解释了 find_package() 方面的工作原理:

                  The more important part for your question is at (2). The find_package() command looks for the GSL libraries, etc. and makes them available as import targets GSL::gsl and GSL::gslcblas. You then use target_link_libraries() to link your executable to them as shown. The CMake documentation explains how the find_package() side of things works in plenty of detail:

                  • 从这里开始:find_package()
                  • GSL 规范:FindGSL 模块
                  • 链接:target_link_libraries()

                  这篇关于在 CMakeLists.txt 中链接 GSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                  How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                  Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                  Delay Loading DLLs(延迟加载 DLL)
                  Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                  Loading a dll from a dll?(从 dll 加载 dll?)

                    <bdo id='YQfqO'></bdo><ul id='YQfqO'></ul>
                      <tbody id='YQfqO'></tbody>
                  • <small id='YQfqO'></small><noframes id='YQfqO'>

                    <legend id='YQfqO'><style id='YQfqO'><dir id='YQfqO'><q id='YQfqO'></q></dir></style></legend>
                    <tfoot id='YQfqO'></tfoot>
                      1. <i id='YQfqO'><tr id='YQfqO'><dt id='YQfqO'><q id='YQfqO'><span id='YQfqO'><b id='YQfqO'><form id='YQfqO'><ins id='YQfqO'></ins><ul id='YQfqO'></ul><sub id='YQfqO'></sub></form><legend id='YQfqO'></legend><bdo id='YQfqO'><pre id='YQfqO'><center id='YQfqO'></center></pre></bdo></b><th id='YQfqO'></th></span></q></dt></tr></i><div id='YQfqO'><tfoot id='YQfqO'></tfoot><dl id='YQfqO'><fieldset id='YQfqO'></fieldset></dl></div>