file-type

在CLion+mingw环境下打包调用C++库的方法

RAR文件

下载需积分: 5 | 72.97MB | 更新于2025-08-03 | 88 浏览量 | 4 下载量 举报 收藏
download 立即下载
在当前的软件开发领域,使用集成开发环境(IDE)来辅助编程已经成为了一种常见的实践,其中CLion作为一个现代化的C++ IDE,因其出色的跨平台开发支持而受到开发者们的青睐。在Windows平台上,通过结合使用CLion和mingw(MinGW即Minimalist GNU for Windows),开发者们可以创建并调用C++动态和静态库,进而打包出完整的应用程序。接下来,我们将详细介绍这一过程涉及的知识点。 ### CLion与mingw的安装与配置 **CLion安装配置:** 1. 访问CLion的官方网站下载CLion的安装包。 2. 根据操作系统需求进行安装。 3. 在安装过程中,需要指定编译器(如mingw)和调试器路径。 4. 安装完毕后,启动CLion并进行初始配置,例如设置项目文件位置、插件等。 **mingw安装配置:** 1. 下载MinGW安装程序,推荐使用MinGW-w64项目提供的安装器。 2. 运行安装程序并选择所需的工具链以及安装目录。 3. 安装过程中,可以指定C++编译器(如g++)和链接器(如ld)。 4. 完成安装后,需要将mingw的bin目录加入到系统的环境变量PATH中,以便在任何位置调用其编译器和工具。 ### 创建C++项目并配置库 **创建项目:** 1. 打开CLion,选择“创建新项目”。 2. 选择C++项目,并根据需要设置项目名称和位置。 3. 在项目创建向导中,指定之前安装的mingw作为项目的编译器。 **配置静态库:** 1. 在CLion中创建一个新的C++库(通常选择静态库)。 2. 添加相应的C++源文件和头文件到静态库项目中。 3. 使用CMake构建系统在CMakeLists.txt中配置静态库编译选项。 4. 构建项目以生成库文件(.lib)和头文件。 **配置动态库:** 1. 创建一个新的C++项目,设置目标为动态链接库。 2. 添加源文件和头文件。 3. 修改CMakeLists.txt配置动态库的编译选项。 4. 构建项目以生成动态库文件(.dll)和头文件。 ### 调用库 **调用静态库:** 1. 在需要使用静态库的项目中,将静态库文件和头文件加入项目。 2. 在项目的CMakeLists.txt中链接静态库,使用target_link_libraries命令。 3. 在源文件中包含静态库提供的头文件,并调用相应的函数或类。 4. 构建项目,确保静态库被正确链接。 **调用动态库:** 1. 同样,将动态库文件和头文件加入到项目中。 2. 在CMakeLists.txt中使用target_link_libraries命令链接动态库。 3. 在源代码中包含头文件,并正确加载和使用动态库。 4. 由于动态库在运行时才被加载,因此可能需要确保动态库在运行程序时的路径被正确设置,或者在代码中动态加载。 ### 打包应用程序 在CLion和mingw的帮助下,一旦动态库和静态库被正确构建并调用,接下来就是将应用程序打包: 1. 使用CLion内置的打包工具或者第三方打包软件将应用程序和所有依赖项组合成一个可执行文件。 2. 如果使用静态库,打包的可执行文件将包含静态库代码,体积较大,但无需担心运行时的库依赖问题。 3. 如果使用动态库,打包时可以包含必要的.dll文件或确保运行时的库路径设置正确,以便程序可以找到动态链接库。 ### 测试与部署 在打包应用程序后,需要进行一系列的测试,以确保应用程序在目标操作系统上能够正常运行。测试完成后,应用程序便可以部署到目标环境中使用了。 综上所述,CLion结合mingw工具链可以为C++开发提供一个强大的跨平台开发环境,通过上述步骤,开发者可以有效地创建、打包并调用C++动态和静态库,构建出高效、稳定的软件产品。注意,在此过程中,合理配置环境和CMakeLists.txt文件是关键,同时正确管理库的依赖关系对于打包后的应用程序能否正常运行也是至关重要的。

相关推荐

filetype

g++.exe E:\SAR\Github\sar-geo-correct\sar_geo-correct_R-D\sar-geo-correct\main.cpp -o main D:\Software\CLion 2024.1\bin\mingw\bin/ld.exe: C:\Users\zhang\AppData\Local\Temp\cckmAxBu.o:main.cpp:(.text+0x73): undefined reference to `SatelliteOrbitFit::GetOrbitParameters(double*, double*, double*, double&, double&, double&, double&, double&, double&)' D:\Software\CLion 2024.1\bin\mingw\bin/ld.exe: C:\Users\zhang\AppData\Local\Temp\cckmAxBu.o:main.cpp:(.text+0x34a): undefined reference to `SatelliteOrbitFit::OrbitInterpolation(double*, double*, double*)' D:\Software\CLion 2024.1\bin\mingw\bin/ld.exe: C:\Users\zhang\AppData\Local\Temp\cckmAxBu.o:main.cpp:(.text+0x36a): undefined reference to `SatelliteOrbitFit::OrbitInterpolation(double*, double*, double*)' D:\Software\CLion 2024.1\bin\mingw\bin/ld.exe: C:\Users\zhang\AppData\Local\Temp\cckmAxBu.o:main.cpp:(.text+0x38a): undefined reference to `SatelliteOrbitFit::OrbitInterpolation(double*, double*, double*)' D:\Software\CLion 2024.1\bin\mingw\bin/ld.exe: C:\Users\zhang\AppData\Local\Temp\cckmAxBu.o:main.cpp:(.text+0x420): undefined reference to `ImgData_R_W::ImgRead(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int&, int&, int&, double*)' D:\Software\CLion 2024.1\bin\mingw\bin/ld.exe: C:\Users\zhang\AppData\Local\Temp\cckmAxBu.o:main.cpp:(.text+0x4da): undefined reference to `ImgData_R_W::ImgRead(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int&, int&, int&, double*)' D:\Software\CLion 2024.1\bin\mingw\bin/ld.exe: C:\Users\zhang\AppData\Local\Temp\cckmAxBu.o:main.cpp:(.text+0x74c): undefined reference to `R_DCorrect::CalculateT_azi(double&, double, double, double, double*, double*, double*)' D:\Software\CLion 2024.1\bin\mingw\bin/ld.exe: C:\Users\zhang\AppData\Local\Temp\cckmAxBu.o:main.cpp:(.text+0x7dd): undefined reference to `R_DCorrect::CalculateDEMIJ(int&, int&, double, double*, double*, double*, double, double, double, double)' D:\Software\CLion 2024.1\bin\mingw\bin/ld.exe: C:\Users\zhang\AppData\Local\Temp\cckmAxBu.o:main.cpp:(.text+0xab6): undefined reference to `ImgData_R_W::ImgStore(unsigned short**, int, int, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)' collect2.exe: error: ld returned 1 exit status

filetype

In file included from D:/SelfUsing/Language/CLion 2025.1.3/mingw/lib/gcc/x86_64-w64-mingw32/14.2.0/include/c++/bits/hashtable_policy.h:34, from D:/SelfUsing/Language/CLion 2025.1.3/mingw/lib/gcc/x86_64-w64-mingw32/14.2.0/include/c++/bits/hashtable.h:35, from D:/SelfUsing/Language/CLion 2025.1.3/mingw/lib/gcc/x86_64-w64-mingw32/14.2.0/include/c++/bits/unordered_map.h:33, from D:/SelfUsing/Language/CLion 2025.1.3/mingw/lib/gcc/x86_64-w64-mingw32/14.2.0/include/c++/unordered_map:41, from D:/obj/i wanna own world to me/i wanna own world to me.cpp:9: D:/SelfUsing/Language/CLion 2025.1.3/mingw/lib/gcc/x86_64-w64-mingw32/14.2.0/include/c++/tuple: In instantiation of 'constexpr std::pair<_T1, _T2>::pair(std::tuple<_Args1 ...>&, std::tuple<_Args2 ...>&, std::_Index_tuple<_Indexes1 ...>, std::_Index_tuple<_Indexes2 ...>) [with _Args1 = {std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&}; long long unsigned int ..._Indexes1 = {0}; _Args2 = {}; long long unsigned int ..._Indexes2 = {}; _T1 = const std::__cxx11::basic_string<char>; _T2 = SDL_GL_Image]': D:/SelfUsing/Language/CLion 2025.1.3/mingw/lib/gcc/x86_64-w64-mingw32/14.2.0/include/c++/tuple:2877:63: required from 'constexpr std::pair<_T1, _T2>::pair(std::piecewise_construct_t, std::tuple<_Args1 ...>, std::tuple<_Args2 ...>) [with _Args1 = {std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&}; _Args2 = {}; _T1 = const std::__cxx11::basic_string<char>; _T2 = SDL_GL_Image]' 2877 | typename _Build_index_tuple<sizeof...(_Args2)>::__type()) | ^ D:/SelfUsing/Language/CLion 2025.1.3/mingw/lib/gcc/x86_64-w64-mingw32/14.2.0/include/c++/bits/stl_construct.h:97:14: required from 'constexpr decltype (::new(void*(0)) _Tp) std::construct_at(_Tp*, _Args&& ...) [with _Tp = pair<const __cxx11::basic_string<char>, SDL_GL_Image>; _Args = {const piecewise_construct_t&, tuple<__cxx11::basic_string<char, char_traits<char>, allocator<char> >&&>, tuple<>}; decltype (::new(void*(0)) _Tp) = pair<const __cxx11::basic_string<char>, SDL_GL_Image>*]' 97 | { return ::new((void*)__location) _Tp(std::forward<_Args>(__args)...); } | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ D:/SelfUsing/Language/CLion 2025.1.3/mingw/lib/gcc/x86_64-w64-mingw32/14.2.0/include/c++/bits/alloc_traits.h:536:21: required from 'static constexpr void std::allocator_traits<std::allocator<_Up> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = std::pair<const std::__cxx11::basic_string<char>, SDL_GL_Image>; _Args = {const std::piecewise_construct_t&, std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&>, std::tuple<>}; _Tp = std::__detail::_Hash_node<std::pair<const std::__cxx11::basic_string<char>, SDL_GL_Image>, true>; allocator_type = std::allocator<std::__detail::_Hash_node<std::pair<const std::__cxx11::basic_string<char>, SDL_GL_Image>, true> >]' 536 | std::construct_at(__p, std::forward<_Args>(__args)...); | ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ D:/SelfUsing/Language/CLion 2025.1.3/mingw/lib/gcc/x86_64-w64-mingw32/14.2.0/include/c++/bits/hashtable_policy.h:2024:36: required from 'std::__detail::_Hashtable_alloc<_NodeAlloc>::__node_type* std::__detail::_Hashtable_alloc<_NodeAlloc>::_M_allocate_node(_Args&& ...) [with _Args = {const std::piecewise_construct_t&, std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&>, std::tuple<>}; _NodeAlloc = std::allocator<std::__detail::_Hash_node<std::pair<const std::__cxx11::basic_string<char>, SDL_GL_Image>, true> >; __node_ptr = std::allocator<std::__detail::_Hash_node<std::pair<const std::__cxx11::basic_string<char>, SDL_GL_Image>, true> >::value_type*]' 2024 | __node_alloc_traits::construct(__alloc, __n->_M_valptr(), | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ 2025 | std::forward<_Args>(__args)...); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ D:/SelfUsing/Language/CLion 2025.1.3/mingw/lib/gcc/x86_64-w64-mingw32/14.2.0/include/c++/bits/hashtable.h:312:35: required from 'std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::_Scoped_node::_Scoped_node(std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::__hashtable_alloc*, _Args&& ...) [with _Args = {const std::piecewise_construct_t&, std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&>, std::tuple<>}; _Key = std::__cxx11::basic_string<char>; _Value = std::pair<const std::__cxx11::basic_string<char>, SDL_GL_Image>; _Alloc = std::allocator<std::pair<const std::__cxx11::basic_string<char>, SDL_GL_Image> >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::__cxx11::basic_string<char> >; _Hash = std::hash<std::__cxx11::basic_string<char> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, false, true>; std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::__hashtable_alloc = std::_Hashtable<std::__cxx11::basic_string<char>, std::pair<const std::__cxx11::basic_string<char>, SDL_GL_Image>, std::allocator<std::pair<const std::__cxx11::basic_string<char>, SDL_GL_Image> >, std::__detail::_Select1st, std::equal_to<std::__cxx11::basic_string<char> >, std::hash<std::__cxx11::basic_string<char> >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, false, true> >::__hashtable_alloc]' 312 | _M_node(__h->_M_allocate_node(std::forward<_Args>(__args)...)) | ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ D:/SelfUsing/Language/CLion 2025.1.3/mingw/lib/gcc/x86_64-w64-mingw32/14.2.0/include/c++/bits/hashtable_policy.h:870:42: required from 'std::__detail::_Map_base<_Key, std::pair<const _Key, _Val>, _Alloc, std::__detail::_Select1st, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, true>::mapped_type& std::__detail::_Map_base<_Key, std::pair<const _Key, _Val>, _Alloc, std::__detail::_Select1st, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, true>::operator[](key_type&&) [with _Key = std::__cxx11::basic_string<char>; _Val = SDL_GL_Image; _Alloc = std::allocator<std::pair<const std::__cxx11::basic_string<char>, SDL_GL_Image> >; _Equal = std::equal_to<std::__cxx11::basic_string<char> >; _Hash = std::hash<std::__cxx11::basic_string<char> >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, false, true>; mapped_type = SDL_GL_Image; key_type = std::__cxx11::basic_string<char>]' 870 | typename __hashtable::_Scoped_node __node { | ^~~~~~ D:/SelfUsing/Language/CLion 2025.1.3/mingw/lib/gcc/x86_64-w64-mingw32/14.2.0/include/c++/bits/unordered_map.h:992:20: required from 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::mapped_type& std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&&) [with _Key = std::__cxx11::basic_string<char>; _Tp = SDL_GL_Image; _Hash = std::hash<std::__cxx11::basic_string<char> >; _Pred = std::equal_to<std::__cxx11::basic_string<char> >; _Alloc = std::allocator<std::pair<const std::__cxx11::basic_string<char>, SDL_GL_Image> >; mapped_type = SDL_GL_Image; key_type = std::__cxx11::basic_string<char>]' 992 | { return _M_h[std::move(__k)]; } | ~~~~^ D:/obj/i wanna own world to me/i wanna own world to me.cpp:164:57: required from here 164 | glBindTexture(GL_TEXTURE_2D, images["sprBrownBlock"s].textureID); | ^ D:/SelfUsing/Language/CLion 2025.1.3/mingw/lib/gcc/x86_64-w64-mingw32/14.2.0/include/c++/tuple:2888:9: error: no matching function for call to 'SDL_GL_Image::SDL_GL_Image()' 2888 | second(std::forward<_Args2>(std::get<_Indexes2>(__tuple2))...) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ D:/obj/i wanna own world to me/i wanna own world to me.cpp:43:14: note: candidate: 'SDL_GL_Image::SDL_GL_Image(const char*)' 43 | explicit SDL_GL_Image(const char* path) { | ^~~~~~~~~~~~ D:/obj/i wanna own world to me/i wanna own world to me.cpp:43:14: note: candidate expects 1 argument, 0 provided D:/obj/i wanna own world to me/i wanna own world to me.cpp:39:7: note: candidate: 'constexpr SDL_GL_Image::SDL_GL_Image(const SDL_GL_Image&)' 39 | union SDL_GL_Image { | ^~~~~~~~~~~~ D:/obj/i wanna own world to me/i wanna own world to me.cpp:39:7: note: candidate expects 1 argument, 0 provided ninja: build stopped: subcommand failed.

as_chengge
  • 粉丝: 28
上传资源 快速赚钱