在C++中,大多数lib都是Debug/Release版本.问题1.调试版和发布版之间有什么大的区别(例如,使用一个版本与另一个版本有什么优势).
问题2. lib只是有一个函数的实现,如果你使用调试/发布版本,函数实现如何改变?
问题3.您是否可以在调试模式下构建应用程序并使用lib的发行版本?
谢谢.
我似乎对 C++ 中的语言环境有问题。当我从 Eclipse 中运行我的程序时,一切正常。但是,当我尝试从命令行运行时,我不断收到此错误:
失败:locale::facet::_S_create_c_locale 名称无效
这是触发错误的代码:
// Set up UTF8 file stream
string fileName = "./sz.txt";
wifstream inFileStream;
try {
setlocale(LC_ALL, "");
inFileStream.open(fileName.c_str());
inFileStream.imbue(locale(""));
if(!inFileStream) {
return EXIT_FAILURE;
}
}
catch (const std::exception &exc) {
wcout << "Error while trying to create UTF8 file stream." << endl;
std::cerr << exc.what() << endl;
if( inFileStream.is_open() )
inFileStream.close();
return EXIT_FAILURE;
}
Run Code Online (Sandbox Code Playgroud)
“locale”的输出如下:
LANG="de_DE.UTF-8"
LC_COLLATE="de_DE.UTF-8"
LC_CTYPE="de_DE.UTF-8"
LC_MESSAGES="de_DE.UTF-8"
LC_MONETARY="de_DE.UTF-8"
LC_NUMERIC="de_DE.UTF-8"
LC_TIME="de_DE.UTF-8"
LC_ALL="de_DE.UTF-8"
Run Code Online (Sandbox Code Playgroud)
我还尝试使用“de_DE.UTF-8”作为语言环境字符串而不是“”(实际上应该是这样),但这给了我同样的错误。
奇怪的是,该程序在 Eclipse 中运行时运行良好。我正在使用 g++ 从命令行编译以下版本:
配置:--prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM …
--disable-hosted-libstdcxx
only build freestanding C++ runtime support
Run Code Online (Sandbox Code Playgroud)
从<gcc>/libstdc++-v3/configure --help.
这种独立模式是什么,有什么限制和好处?
对于我所知的很少,它看起来相当于 libstdc++ 的一些静态链接,但是如果您可以构建您的 *.a 库,那么这种“模式”的意义何在?这听起来不是一个很好的解释。
我有一个我试图在 Linux 下构建的 c++ 应用程序,它需要链接到第三方共享库,但是这个库是使用最新版本的 GCC/glibc (4.8.3/2.18) 构建的。当我尝试使用较新版本的 GCC/glibc (4.4.7/2.12) 构建我的应用程序时,构建的链接阶段失败,ld 抱怨未定义的引用,这些引用是对较新的 libstdc++ 中定义的函数的引用。
第三方给了我一个预编译版本的 libstdc++ 和 libgcc_s 来与库一起使用,但是我如何在我的构建中使用这些版本?
我如何告诉 GCC 使用预编译库而不是系统库,同时仍然使用系统 GCC?
我曾尝试使用“-nodefaultlibs”选项并包括“-lstdc++”和“-L”选项,但它似乎对未定义的引用没有影响。
我在链接过程中遇到的错误示例:
undefined reference to std::__throw_bad_function_call()@GLIBCXX_3.4.14'
undefined reference to std::length_error::~length_error()@GLIBCXX_3.4.15'
我clang++用来编译C++代码.我链接到gcc标准的C++库,libstdc++.但是,我libstdc++在我的Ubuntu机器上有几个不同的安装.当我运行时clang++,它使用4.8安装libstdc++:
andy@andy:~$ clang++-3.5 -v
Ubuntu clang version 3.5.0-4ubuntu2~trusty2 (tags/RELEASE_350/final) (based on LLVM 3.5.0)
Target: i386-pc-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/4.6
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/4.6.4
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/4.8
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/4.8.4
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/4.9
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/4.9.3
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.6
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.6.4
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.8.4 …Run Code Online (Sandbox Code Playgroud) 以下代码无法在gcc 5.3下编译(它是从更大的代码片段中获取的简化版本):
#include <unordered_map>
#include <string>
class Foo {
std::unordered_map<std::string, Foo> m; //"self-referential"
};
int main()
{
Foo f;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
出现以下错误:
g++ --std=c++1y -c rh.cpp
In file included from /usr/local/include/c++/5.3.0/utility:70:0,
from /usr/local/include/c++/5.3.0/unordered_map:38,
from rh.cpp:1:
/usr/local/include/c++/5.3.0/bits/stl_pair.h: In instantiation of ‘struct std::pair<const int, Foo>’:
/usr/local/include/c++/5.3.0/ext/aligned_buffer.h:85:34: required from ‘struct __gnu_cxx::__aligned_buffer<std::pair<const int, Foo> >’
/usr/local/include/c++/5.3.0/bits/hashtable_policy.h:246:43: required from ‘struct std::__detail::_Hash_node_value_base<std::pair<const int, Foo> >’
/usr/local/include/c++/5.3.0/bits/hashtable_policy.h:292:12: required from ‘struct std::__detail::_Hash_node<std::pair<const int, Foo>, false>’
/usr/local/include/c++/5.3.0/bits/hashtable_policy.h:1896:60: required from ‘struct std::__detail::_Hashtable_alloc<std::allocator<std::__detail::_Hash_node<std::pair<const int, Foo>, false> …Run Code Online (Sandbox Code Playgroud) 这是我的第一个 cmake 文件。我有一个带有 clang 和 g++ 的 linux 系统。还安装了 libc++。我在 Mac (xcode) 上开发但部署到 linux。我正在编写一个 cmake 文件,我可以在其中选择 clang 或 g++ 和 libc++ 或 libstdc++。所以有 4 种可能的组合。
我想出了如何选择编译器并在其上强制使用 c++11,但我无法弄清楚如何指定标准库。有什么建议?
这是我到目前为止:
## cmake ###
cmake_minimum_required (VERSION 3.5)
#set project directories
set(ProjectDirectory ${CMAKE_SOURCE_DIR}) #.../Project/
set(BuildDirectory ${ProjectDirectory}/Build)
set(ProductDirectory ${ProjectDirectory}/Products)
set(sourceDirectory ${ProjectDirectory}/Source)
#print project directories
message(${ProjectDirectory})
message(${BuildDirectory})
message(${ProductDirectory})
#configure cmake
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ProductDirectory})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${ProductDirectory})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${ProductDirectory})
set(CMAKE_VERBOSE_MAKEFILE on)
#compiler and standard library settings
set(CMAKE_CXX_COMPILER "clang++")
set(CMAKE_CXX_STANDARD 11)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -v -stdlib=libc++")
#libstdc++ #linux
#libc++ #OS X …Run Code Online (Sandbox Code Playgroud) 当我查看 GNU 库的实现(好吧,主要是 libstdc++)时,我可以看到命名中有重复出现的模式。模板类型被命名_Tp,成员有前缀_M_,一些标记有双下划线等。我试图找到有关命名约定的文档,但无济于事。GNU 有一个样式指南,它也在代码中遵循,但更像是这个命名约定的一个子集。
你知道关于 GNU gcc 库实现的样式细节的任何文档吗?
提前致谢。
我尝试使用std::reduce函子来计算数组中的字符数。GCC 在 MSVC 中编译和工作时出错。链接在这里
#include <iostream>
#include <array>
#include <numeric>
#include <cstring>
int main()
{
std::array arr{ "Mickey","Minnie","Jerry" };
struct StringLength
{
auto operator()(const char* l, size_t r)
{
return strlen(l) + r;
}
auto operator()(size_t l, const char* r)
{
return l + strlen(r);
}
auto operator()(const char* l, const char* r)
{
return strlen(l) + strlen(r);
}
auto operator()(size_t l, size_t r)
{
return l + r;
}
};
std::cout << std::reduce(arr.begin(), arr.end(), size_t{}, StringLength()); …Run Code Online (Sandbox Code Playgroud) 我可以使用std::begin()and创建开始和结束迭代器std::end()。
例如:
int arr[4][4] = <something here>;
auto begin_it = std::begin(arr);
auto end_it = std::end(arr);
Run Code Online (Sandbox Code Playgroud)
但是,为什么我们没有std::front()和std::back()。是否有任何特定原因可以省略它们?
我可以使用任何类似的功能(当然除了开始和结束)?