我想针对另一个静态库对程序进行静态编译,对于本示例,我正在使用zeromq。这是我的CMakeLists.txt
cmake_minimum_required(VERSION 2.6)
add_executable( test test.cpp )
find_library(ZMQ NAMES libzmq.a)
message(STATUS ${ZMQ})
target_link_libraries( test ${ZMQ} )
Run Code Online (Sandbox Code Playgroud)
.a
我运行时会找到文件mkdir build && cd build && cmake ..
-- /usr/local/lib/libzmq.a
Run Code Online (Sandbox Code Playgroud)
但是,如果我检查link.txt
文件,该库是动态链接的:
/usr/bin/c++ CMakeFiles/test.dir/test.cpp.o \
-o test -rdynamic /usr/local/lib/libzmq.a
Run Code Online (Sandbox Code Playgroud)
奇怪的是,如果我将文件移动到另一个目录,说/usr/lib
再运行cmake ..
一次,它将找到该库的新路径:
-- /usr/lib/libzmq.a
Run Code Online (Sandbox Code Playgroud)
但是现在它神奇地变成了静态链接:
/usr/bin/c++ CMakeFiles/test.dir/test.cpp.o \
-o test -rdynamic -Wl,-Bstatic -lzmq -Wl,-Bdynamic
Run Code Online (Sandbox Code Playgroud)
同样的事情也适用于我链接到的其他库。
为什么我所有的库都/usr/local/lib
被动态链接?
在我的每一篇 Jekyll 帖子中,我都在前面列出了一个数字:
---
minutes: X
---
Run Code Online (Sandbox Code Playgroud)
该值始终与 post-to-post 不同,我想找到所有帖子的总和。
不确定这是否可能或应该采用什么方法。
提前感谢您的任何帮助!
我通过这个添加了增强:
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
project(APP C CXX)
add_executable(APP src.cpp)
target_link_libraries(APP ${Boost_LIBRARIES})
Run Code Online (Sandbox Code Playgroud)
当我编译源代码时,我得到:
demo.cpp:(.text+0x3d3): undefined reference to `boost::system::generic_category()'
Run Code Online (Sandbox Code Playgroud)
我检查了拼写(Boost_LIBRARIES与BOOST_LIBRARIES),但是还可以。
我在Fedora中使用boost-devel软件包安装了boost。
我创建了一个在用户选择后计算秒数的函数。这一切都有效,但是可以更智能、更高效地完成吗?因为它看起来很重而且很慢。有没有一个lib可以解决这个问题?或者我们怎样才能绕过它?
这是我的代码:
#include <ctime>
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
double a,c, x,b;
int nutid=0;
cout<<"Please enter a number: ";
cin>>a;
x = time(0);
c = a-1;
while (true) {
if (!cin) {
cout<<"... Error";
break;
}
else {
b=time(0)-x;
if(b>nutid){
cout<<setprecision(11)<<b<<endl;
nutid = b+c;
}
}
}
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我阅读了有关智能指针,移动语义和迭代器的所有可能的引用,但我仍然在努力理解为什么以下C++ 14代码段错误:
#include <iostream>
#include <vector>
#include <memory>
using namespace std;
int main(int argc, char **argv)
{
vector<unique_ptr<int>> ints (10);
for(int i = 0; i < 10; ++i) {
unique_ptr<int> number = make_unique<int>(5);
ints.push_back(move(number));
}
for(auto& n : ints) {
cout << *n << endl;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译:
g++ <filename> -std=c++14 -o <executable>
Run Code Online (Sandbox Code Playgroud) 我正在尝试用C++运行我的第一个opengl程序,它打开一个窗口,设置一个背景颜色,并从Mac OS X上的终端给出一个标题.
代码编译和链接很好.当我运行程序时,窗口和标题打开很好,但背景颜色总是黑色.
我的理解是该功能glClearColor
设置背景颜色.但是,无论我传递给函数的参数是什么,窗口的背景颜色总是黑色.
如果有人能向我解释我正在犯的错误,我将非常感激.谢谢,以下是代码:
#include <iostream>
#define GLEW_STATIC
#include <GL/glew.h>
#include <GLFW/glfw3.h>
const GLint WIDTH = 800, HEIGHT = 600;
int main()
{
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "Learn OpenGL", nullptr, nullptr);
int screenWidth, screenHeight;
glfwGetFramebufferSize(window, &screenWidth, &screenHeight);
if(nullptr == window)
{
std::cout << "Failed to create GLFW window" << '\n';
glfwTerminate();
return -1;
}
glewExperimental = GL_TRUE;
GLenum err=glewInit();
if(err != glewInit())
{
std::cout …
Run Code Online (Sandbox Code Playgroud) 这很简单,我不知道为什么我遇到麻烦.我试图模仿两张图像之间的翻转卡,所以当点击时,它只会改变为另一张图像.我的if/else语句有问题,因为每次单击图像时,它都不会进入else部分.在HTML页面的源代码中,图像的src正在被更改,但每次都传递if语句.
(function() {
// attaches event handler to image
window.onload = function() {
var image1 = document.getElementById("image1");
image1.onclick = changeImage;
};
// changes image when clicked to flip from image to text and text to image
function changeImage() {
if (document.getElementById("image1").src = "img/top.png") {
document.getElementById("image1").src = "img/toptext.png";
//window.alert('hi');
}
else {
window.alert('it passed');
document.getElementById("image1").src="img/top.png";
}
}
})();
Run Code Online (Sandbox Code Playgroud) 如何在GitHub页面上使用'jekyll-multiple-languages-plugin'?
它在本地工作,但是当我将源推送到GitHub时出现以下错误:
The tag `t` on line 6 in `about.html` is not a recognized Liquid tag.
Run Code Online (Sandbox Code Playgroud)
导致错误的代码是:
{% t about.title %}
Run Code Online (Sandbox Code Playgroud) 我知道您不能使用operator+
将整数连接到 astd::string
而不将其转换为 achar*
或std::string
。
但是为什么添加一个整数会返回字符串的尾部呢?
#include <iostream>
#include <string>
int main()
{
std::string x;
x = "hello world" + 3;
std::cout << x << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
印刷: lo world
如果你改变: x = "hello world" + 8;
我们打印: rld
这背后的原因是什么?未定义的行为?
在 Qt 中,当尝试分配引用时出现use of deleted function
错误:
/home/niko/QT_snippets/QML1/users.cpp:16: error: use of deleted function 'User::User(const User&)'
User user=users_map.value("email@domain.com");
^
^
/home/niko/QT_snippets/QML1/users.h:7: In file included from ../QML1/users.h:7:0,
/home/niko/QT_snippets/QML1/users.cpp:1: from ../QML1/users.cpp:1:
/home/niko/QT_snippets/QML1/user.h:6: 'User::User(const User&)' is implicitly deleted because the default definition would be ill-formed:
class User : public QObject
^
/opt/Qt/5.7/gcc_64/include/QtCore/QObject:1: In file included from /opt/Qt/5.7/gcc_64/include/QtCore/QObject:1:0,
/home/niko/QT_snippets/QML1/users.h:4: from ../QML1/users.h:4,
/home/niko/QT_snippets/QML1/users.cpp:1: from ../QML1/users.cpp:1:
Run Code Online (Sandbox Code Playgroud)
在 C 中,我总是使用指针,从来没有遇到过任何问题,但正如我在 C++ 中看到的那样,每个人都使用引用。
我应该如何在 Qt 中通过引用分配对象?例如,在这一行中,我应该如何使对象成为对对象user
中值的引用?users_map
User user=users_map.value("email@domain.com");
Run Code Online (Sandbox Code Playgroud)
或者也许是以下内容?
User user=&users_map.value("email@domain.com");
Run Code Online (Sandbox Code Playgroud)
因为...上面的代码无法编译。我需要在Users
类的方法内部使用它来访问变量中的数据users_map …