小编Cha*_*Kim的帖子

qmake如何确定要在Makefile中使用的编译器?

qt源附带了一些示例.从互联网下载之后,我转到examples/painting/concentriccircles并运行'qmake'并从.pro文件生成Makefile(设置CC = gcc),在make之后,我可以运行demo程序concentriccircles我的CentOS机器.(运行x86代码).

现在我有一个在运行操作系统的sparc机器上运行Qt的项目,我已经设置了构建树.如果我将整个concentriccircles目录移动到构建树中的某个位置,当我运行'qmake'时,生成的Makefile设置CC = sparc-xxx-gcc而不是普通的gcc(用于x86主机).事实上,如果我没有移动目录,如果我从sparc构建树运行qmake,它就会为sparc创建Makefile.(不管.pro文件)

qmake如何知道我正在从运行qmake的位置构建sparc机器的qt程序?下面是concentriccircles.pro文件.

HEADERS       = circlewidget.h \
                window.h
SOURCES       = circlewidget.cpp \
                main.cpp \
                window.cpp

# install
target.path = $$[QT_INSTALL_EXAMPLES]/painting/concentriccircles
sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS concentriccircles.pro
sources.path = $$[QT_INSTALL_EXAMPLES]/painting/concentriccircles
INSTALLS += target sources

symbian {
    TARGET.UID3 = 0xA000A64A
    include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
}
maemo5: include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri)
Run Code Online (Sandbox Code Playgroud)

qt makefile qt4

3
推荐指数
1
解决办法
5095
查看次数

在Python中公开C++类(只能加载ET_DYN和ET_EXEC)

我在这里看看如何向Python公开c ++.我已经构建了Python深度学习代码,它使用boost-python连接c ++和python,它运行正常,所以我的系统有boost-python alread设置的东西.这里是我的HELLO.CPP代码(我曾经WorldC和WorldP清楚地显示在声明中C++和Python的类名称的使用.我不知道为什么原始网页使用相同的类名World引起混乱初学者. )

#include <boost/python.hpp>
using namespace boost::python;

struct WorldC
{
    void set(std::string msg) { this->msg = msg; }
    std::string greet() { return msg; }
    std::string msg;
};

BOOST_PYTHON_MODULE(hello)
{
    class_<WorldC>("WorldP")
        .def("greet", &WorldC::greet)
        .def("set", &WorldC::set)
    ;
}
Run Code Online (Sandbox Code Playgroud)

这就是我打招呼的方式.所以

g++ -shared -c -o hello.so -fPIC hello.cpp -lboostpython -lpython2.7 -I/usr/local/include/python2.7
Run Code Online (Sandbox Code Playgroud)

当我在python中运行import hello时,它给了我这个错误.

>>> import hello
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: ./hello.so: only ET_DYN and ET_EXEC can be loaded
Run Code Online (Sandbox Code Playgroud)

谁能告诉我什么是错的? …

python boost

3
推荐指数
1
解决办法
3023
查看次数

我无法理解 std::istream_iterator 的用法

我无法理解下面的代码。

(来自https://www.boost.org/doc/libs/1_74_0/more/getting_started/unix-variants.html

#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>

int main()
{
    using namespace boost::lambda;
    typedef std::istream_iterator<int> in;

    std::for_each(
        in(std::cin), in(), std::cout << (_1 * 3) << " " );
}
Run Code Online (Sandbox Code Playgroud)

该网页没有对代码进行任何解释。

我无法理解的是功能线std::for_each

std::for_each定义如下。

template <class InputIterator, class Function>
Function for_each(InputIterator first, InputIterator last, Function fn);
Run Code Online (Sandbox Code Playgroud)

所以first就是in(std::cin)last就是in(),就是function这个cout陈述。

谁能向我解释示例代码中的语法和含义firstlast

迭代first器似乎是用初始值构造的,但是最后一个值std::cin有什么用呢?in()

我也无法理解该_1部分。

该程序输出3 …

c++ boost iterator istream-iterator

3
推荐指数
1
解决办法
1933
查看次数

为什么在arm64引导代码__primary_switched中将init_task结构体地址保存到sp_el0?

这是来自 linux arm64 (arch/arm64/kernel/head.S) 的汇编代码。(内核源代码 5.4.21)

__primary_switched:
    adrp    x4, init_thread_union   -- line 1
    add sp, x4, #THREAD_SIZE        -- line 2
    adr_l   x5, init_task           -- line 3
    msr sp_el0, x5          // Save thread_info   -- line 4
    adr_l   x8, vectors         // load VBAR_EL1 with virtual  -- line5
    msr vbar_el1, x8            // vector table address  -- line 6
    isb                    -- line7
    
    stp xzr, x30, [sp, #-16]!            -- line8
    mov x29, sp                   -- line9
    
    str_l   x21, __fdt_pointer, x5      // Save FDT pointer   -- line10 …
Run Code Online (Sandbox Code Playgroud)

boot assembly linux-kernel arm64

3
推荐指数
1
解决办法
1517
查看次数

如何编译裸机hello_world.c并在qemu-system-aarch64上运行它?

如标题所示,我想编译hello_world.c程序并在qemu-system-aarch64上运行它。这是程序:

#include <stdio.h>
int main()
{
printf("hello world!\n");
}
Run Code Online (Sandbox Code Playgroud)

https://releases.linaro.org/components/toolchain/binaries/latest-7/aarch64-elf/(这是裸机目录),我可以看到这些工具链:

folder  aarch64-elf -       
folder  aarch64-linux-gnu   -       
folder  aarch64_be-elf  -       
folder  aarch64_be-linux-gnu    -       
folder  arm-eabi    -       
folder  arm-linux-gnueabi   -       
folder  arm-linux-gnueabihf -       
folder  armeb-eabi  -       
folder  armeb-linux-gnueabi -       
folder  armeb-linux-gnueabihf   -       
folder  armv8l-linux-gnueabihf
Run Code Online (Sandbox Code Playgroud)

所以我选择了aarch64-elf(这是正确的吗?)并将其安装在我的ubuntu 16.04机器上并将bin目录添加到路径中。如果我这样做,aarch64-elf-gcc hello_world.c我会收到 _exit、_sbrk、_write、_close、_lseek、_read、_fstat、_isatty 函数的未定义引用错误。所以我尝试添加 -spec=aem.ve-specs 并且它没有抱怨(我不确定这是否正确)。我尝试运行 qemu。

qemu-system-aarch64 -M virt -cpu cortex-a57 -nographic -smp 1 -m 2048 -kernel a.out
Run Code Online (Sandbox Code Playgroud)

它没有给我任何打印。我应该在这里改变什么?

linux qemu bare-metal linux-kernel arm64

3
推荐指数
1
解决办法
5336
查看次数

在 C 或 C++ 中,如何防止头文件中先前的 #define 影响以后包含的另一个头文件?

我认为可能没有办法避免这种情况,只能更改函数/宏名称,但我在这里问以防万一。

我遇到了一个奇怪的情况。

我正在尝试(刚刚开始)修改程序 A(针对动态库),以便程序使用程序 B 中的函数(这与此问题无关,但程序 A 是基于multi2sim是我同事写的,程序B是qemu,著名的CPU/机器模拟器)。

driverA.cc程序 A 中的文件如下所示:

#include "includeA.h"

#ifdef USED_IN_QEMU
#include "includeB.h"
#endif

// some code...
Run Code Online (Sandbox Code Playgroud)

includeA.h 有一个这样的宏:

#define set_pc(x) \
  do { p->check_pc_alignment(x); \
       npc = sext_xlen(x); \
     } while(0)
Run Code Online (Sandbox Code Playgroud)

但是includeB.h有这个代码:

static inline void cpu_set_pc(CPUState *cpu, vaddr addr)
{
    CPUClass *cc = CPU_GET_CLASS(cpu);
                 
    cc->set_pc(cpu, addr);
} 
Run Code Online (Sandbox Code Playgroud)

编译器抱怨set_pc()根据 应该只接受一个参数includeA.h,但set_pc()inincludeB.h需要两个参数。我知道它只是同名但不同的函数或宏,但是包含文件之间出现了冲突。编译器不知道它们属于不同的世界。

如何避免这种编译错误?

c c++ gcc compiler-errors c-preprocessor

3
推荐指数
1
解决办法
75
查看次数

如何在C中使用宏替换函数

有时,在我从Linux驱动程序中借用的C代码中,我想将一些宏更改为我可以在我的环境中使用的函数.但是这个以前的宏可以采用3或4个参数.
例如,如果我想要替代

SMSC_TRACE(pdata, probe, "Driver Parameters:");   // 3 arguments  
Run Code Online (Sandbox Code Playgroud)

printf("Driver Parameters:");  
Run Code Online (Sandbox Code Playgroud)

替代

SMSC_TRACE(pdata, probe, "LAN base: 0x%08lX", (unsigned long)pdata->ioaddr); // 4 arguments  
Run Code Online (Sandbox Code Playgroud)

printf("LAN base: 0x%08lX", (unsigned long)pdata->ioaddr);  
Run Code Online (Sandbox Code Playgroud)

我怎么做?我试过了

#define SMSC_TRACE((a), (b), (c)) printf((c))  
#define SMSC_TRACE((a), (b), (c), (d)) printf((c), (d))  
Run Code Online (Sandbox Code Playgroud)

但它似乎没有用.只有最后一个似乎生效.

编辑:这似乎也许.

#define SMSC_TRACE(pdata, nlevel, fmt, args...) printf(fmt "\n", ##args)
Run Code Online (Sandbox Code Playgroud)

c macros

2
推荐指数
1
解决办法
184
查看次数

使用两个参数初始化 STL 向量

我看到了如何在 C++ 中初始化向量,但找不到相同的情况,所以我在这里询问。

这个表情是什么?它不是二维向量(我的意思是向量的向量)。它声明了一个包含两个元素的向量吗?

vector<int> mult_dims(1, 2);
Run Code Online (Sandbox Code Playgroud)

c++ stl vector

2
推荐指数
1
解决办法
1万
查看次数

使用定义的常量(来自Makefile)在C中形成变量名的一部分

是否可以使用定义的常量在C中形成变量名的一部分?常量由Makefile定义.(实际上我想通过make参数传递它,如下所示)
例如,我想定义一个数字NUM并使用它声明一个变量.

#define NUM 5
/* I want to declare as below
int var5 
using defined constant `NUM` above
*/
Run Code Online (Sandbox Code Playgroud)

我试过了

int var ## NUM;
Run Code Online (Sandbox Code Playgroud)

但##连接仅用于预处理宏操作,但不起作用.
实际上,常量NUM是从myfile中传入的(通过CFLAGS + = -DNUM = 5).
我怎样才能做到这一点?

ADD1

根据Shachar Shemesh的回答,我试过这个.

=== test.c

#include <stdio.h>

#define compound_id(name1, name2) name1##name2
int compound_id(mynum, NUM);

main()
{
mynum5 = 5;
printf("NUM = %d\n", NUM);
printf("mynum5 = %d\n", mynum5);
Run Code Online (Sandbox Code Playgroud)

== Makefile

ifeq ($(NUM),5)
CFLAGS+=-DNUM=$(NUM)
endif
Run Code Online (Sandbox Code Playgroud)

==命令

make test NUM=5
Run Code Online (Sandbox Code Playgroud)

我得到以下结果:

ckim@stph45:/tmp] make test NUM=5
cc …
Run Code Online (Sandbox Code Playgroud)

c c++ makefile

2
推荐指数
1
解决办法
701
查看次数

aarch64 是否有不可缓存(=缓存旁路)加载或存储指令?

在sparc架构中,有一个ASI(地址空间指示符)被传递给加载、存储指令,因此如果ASI为0x20,则像IO访问一样绕过缓存。即使内存范围在页表中设置为可缓存,缓存也会被绕过。这有时非常方便,例如使用变量在核心之间进行同步等
。aarch64 架构中有类似的东西吗?我查看了指令内容,但在加载/存储指令列表中找不到任何内容。

assembly arm memory-address cpu-cache arm64

2
推荐指数
1
解决办法
1694
查看次数