这似乎是一个简单的问题,我想知道为什么谷歌搜索没有提供任何帮助 - 也不是在StackOverflow,也不是在教程中.我只需要使用bash检查条件是否为假.
我发现我试过的
if ! [ 0==2 ]; then echo Hello; fi
Run Code Online (Sandbox Code Playgroud)
和
if [ ! 0==2 ]; then echo Hello; fi
Run Code Online (Sandbox Code Playgroud)
他们都没有打印Hello.
我发现只有两个类似的问题,但两种情况下的最终答案都是重组代码,不使用"错误"条件.
我正在尝试为Windows编译一个简单的应用程序:
#include <thread>
void Func(){
return;
}
int main(){
std::thread thr1(Func);
thr1.detach();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这就是我得到的:
$ i686-w64-mingw32-g++ -static-libstdc++ -static-libgcc -pipe -g -std=c++0x ./threadstutor.cpp
./threadstutor.cpp: In function ‘int main()’:
./threadstutor.cpp:8:3: error: ‘thread’ is not a member of ‘std’
./threadstutor.cpp:8:15: error: expected ‘;’ before ‘thr1’
./threadstutor.cpp:9:3: error: ‘thr1’ was not declared in this scope
Run Code Online (Sandbox Code Playgroud)
实际上,如果使用g ++为Ubuntu编译,这段代码没有这样的问题; 但是我需要为Windows进行交叉编译,而在这里我被卡住了.
我第一次使用 unix 套接字,我偶然发现了 unix 套接字文件没有被自动删除的问题。看来,在创建套接字后,我不能只是退出程序,而应该删除套接字文件。
但是为什么套接字文件在创建它的程序退出后没有被破坏?看起来应该有办法以某种方式将应用程序连接到这个剩余的文件,或者为什么它仍然存在?
下面是一个代码来说明(它创建一个unix套接字然后退出):
#include <cstdio>
#include <sys/socket.h>
#include <sys/un.h>
int CreateSocket(const char* filename) {
if (strlen(filename) > sizeof(sockaddr_un::sun_path)) {
puts("Too long filename!");
return -1;
}
int fdSock = socket(AF_UNIX, SOCK_DGRAM, 0);
if(fdSock == -1){
perror("socket");
return -1;
}
sockaddr_un server;
server.sun_family = AF_UNIX;
strcpy(server.sun_path, filename);
if(bind(fdSock, (sockaddr*)&server, sizeof(sockaddr_un)) == -1){
perror("socket");
return -1;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我发现,由于某些未知原因焦点在编辑控件中,Escape键永远不会产生消息.下面是创建父窗口的代码,以及它上面的Edit控件.在MyCallBckProcedure()中,我将printf()放在*WM_COMMAND*下,以捕获由Edit生成的消息.更多 - 我甚至试图打印MyCallBckProcedure()中捕获的所有消息; 但如果专注于编辑,则转义键永远不会产生任何消息.这可能是个奇怪的问题?
#include <iostream>
#include <windows.h>
#include <stdio.h>
#define IDC_MAIN_EDIT 101
LRESULT __stdcall MyCallBckProcedure( HWND window, unsigned msg, WPARAM wp, LPARAM lp ){
printf("%x ",msg);
switch(msg){
case WM_COMMAND://here should be catched the escape key of Edit
printf("%x ",msg);
break;
case WM_KEYDOWN:
printf("%x ",msg);
if(wp == VK_ESCAPE)PostQuitMessage(0);
break;
case WM_DESTROY:
std::cout << "\ndestroying window\n" ;
PostQuitMessage(0);
return 0;
default:
return DefWindowProc( window, msg, …Run Code Online (Sandbox Code Playgroud) 假设我有两个源文件--UndefErr.cpp:
#include <cstdio>
void UndefFunc();
void Func2(){UndefFunc();}
void Func1(){printf("Hi\n");}
Run Code Online (Sandbox Code Playgroud)
而main.cpp:
void Func1();
int main(){
Func1();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
正如您在UndefErr.cpp中看到的那样,Func2()将使用undefined来触发错误UndefFunc().不过主要功能并不关心Func2()!根据一个相关的问题,我可以将一个选项--unresolved-symbols = ignore-in-object-files传递给链接器,但我想要一个不同的东西.我需要一个链接器来知道未定义的函数是否在某处使用,然后才会失败.
提出这样一个奇怪问题的原因是我正在尝试使用lwIP,并且很难理解它的所有依赖关系(我只需要TCP/IP),而且我无法在互联网上找到教程.所以我认为我可以单独编译大多数(或所有) .c文件,并编写一些简单的测试来查看它的作用.但是这种方法偶然发现了"未定义的引用",其中大多数可能与用例无关.
Emacs始终将已删除/已删除的内容复制到剪贴板.我经常需要将内容复制并粘贴到Emacs中,但是当我在粘贴之前从Emacs中删除现有内容时,我想要粘贴的内容将丢失.
我找到的唯一解决方案是使用
(setq save-interprogram-paste-before-kill t)
Run Code Online (Sandbox Code Playgroud)
为了确保在Emacs之外复制的内容在kill-ring中保持可用,并且具有类似问题的人似乎对此解决方案感到满意.令我困扰的是,我必须输入C-y 一次或多次重复 M-y才能获得我要粘贴的内容.
所以我的问题是:当我杀死/删除它时,如何阻止Emacs将内容复制到剪贴板(不包括删除区域的情况C-w)?
我遇到过一个我见过的最奇怪的问题.我正在为Linux上的Linux CPU交叉编译应用程序.我正在使用buildroot,一切顺利,直到我试图在目标上运行应用程序:我得到了-sh: ./hw: not found.例如:
$ cat /tmp/test.cpp
#include <cstdio>
#include <vector>
int main(int argc, char** argv){
printf("Hello Kitty!\n");
return 0;
}
$ ./arm-linux-g++ -march=armv7-a /tmp/test.cpp -o /tftpboot/hw
Run Code Online (Sandbox Code Playgroud)
将可执行文件加载到目标; 然后发布目标:
# ./hw
-sh: ./hw: Permission denied
# chmod +x ./hw
# ./hw
-sh: ./hw: not found
# ls -l ./hw
-rwxr-xr-x 1 root root 6103 Jan 1 03:40 ./hw
Run Code Online (Sandbox Code Playgroud)
还有更多:在使用发行版编译器构建时arm-linux-gnueabi-g++ -march=armv7-a /tmp/test.cpp -o /tftpboot/hw,应用运行正常!
我比较了可执行文件readelf -a -W /tftpboot/hw,但没有发现太多的差异.我在这里粘贴了两个输出.我注意到的唯一一件事就是线Version5 EABI, …
我正在编写一个小学生项目,并遇到了一个问题,即我有几个全局变量并且需要在几个源文件中使用它,但是我收到错误 *未定义对 variable_name 的引用*。例如,让我们创建三个源文件:
tst1.h:
extern int global_a;
void Init();
Run Code Online (Sandbox Code Playgroud)
tst1.cpp:
#include "tst1.h"
void Init(){
global_a = 1;
}
Run Code Online (Sandbox Code Playgroud)
tst2.cpp:
#include "tst1.h"
int main(){
Init();
}
Run Code Online (Sandbox Code Playgroud)
当我编译和链接时,这就是我得到的:
$ g++ -c tst1.cpp
$ g++ -c tst2.cpp
$ g++ tst2.o tst1.o
tst1.o: In function `Init()':
tst1.cpp:(.text+0x6): undefined reference to `global_a'
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
如果我删除extern语句,那么我会遇到另一个问题,让我展示一下:
$ g++ -c tst1.cpp
$ g++ -c tst2.cpp
$ g++ tst2.o tst1.o
tst1.o:(.bss+0x0): multiple definition of `global_a'
tst2.o:(.bss+0x0): first defined here
collect2: …Run Code Online (Sandbox Code Playgroud) 该configure脚本是这样启动的
./configure --with-python=yes --host=arm-linux-gnueabi
Run Code Online (Sandbox Code Playgroud)
这样,python就启用了。另外,在配置脚本的日志中,我没有发现任何与 python 相关的不良内容。但无论如何,编译后的 gdb 一直说
$ ./gdb -q
/home/constantine/.gdbinit:7: Error in sourced command file:
ind_string_in_backtrace (gdb.Function)::1: Error in sourced command file:
Undefined command: "class". Try "help".
(gdb) py print("hello")
Python scripting is not supported in this copy of GDB.
Run Code Online (Sandbox Code Playgroud)
我输入 gdb 后看到的错误也与 Python (自动启动时加载的脚本)有关。我确实尝试过make clean,但没有帮助。我希望有人知道解决方案,我真的需要一个脚本,因此需要 python。
显然不是最流行的情况,但我有许多提交,我想在其消息中追加一行Reviewed-by: user<mail>。
到目前为止,我只发现这个命令对我来说失败了Invalid line: 10: Reviewed-by: User <mail>
GIT_EDITOR='git interpret-trailers --trailer "Reviewed-by: User <mail>" --in-place' git rebase -i HEAD~8
Run Code Online (Sandbox Code Playgroud)
我也在IRC上问过,没有结果。
欢迎任何其他建议。