小编Kag*_*sen的帖子

CMake:C编译器无法编译简单的测试程序

我正在尝试针对Mips处理器交叉编译Azure IoT SDKC。使用较旧版本的CMake(2.8.12.2)交叉编译同一SDK的较旧版本是否可以正常工作,因此我怀疑它本身就是代码。我猜这是Mips GCC编译器。

错误信息:

CMake Error at /usr/share/cmake-3.10/Modules/CMakeTestCCompiler.cmake:52 (message):
  The C compiler

    "/usr/local/mipsisa32r2el/r23/bin/mipsisa32r2el-axis-linux-gnu-gcc"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/axis/azure-iot-sdk-c/cmake/iotsdk_linux/CMakeFiles/CMakeTmp

    Run Build Command:"/usr/bin/make" "cmTC_2cc84/fast"
    /usr/bin/make -f CMakeFiles/cmTC_2cc84.dir/build.make CMakeFiles/cmTC_2cc84.dir/build
    make[1]: Entering directory '/home/axis/azure-iot-sdk-c/cmake/iotsdk_linux/CMakeFiles/CMakeTmp'
    Building C object CMakeFiles/cmTC_2cc84.dir/testCCompiler.c.o
    /usr/local/mipsisa32r2el/r23/bin/mipsisa32r2el-axis-linux-gnu-gcc --sysroot=/usr/local/mipsisa32r2el/r23    -o CMakeFiles/cmTC_2cc84.dir/testCCompiler.c.o   -c /home/axis/azure-iot-sdk-c/cmake/iotsdk_linux/CMakeFiles/CMakeTmp/testCCompiler.c
    Linking C executable cmTC_2cc84
    /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_2cc84.dir/link.txt --verbose=1
    /usr/local/mipsisa32r2el/r23/bin/mipsisa32r2el-axis-linux-gnu-gcc --sysroot=/usr/local/mipsisa32r2el/r23      -rdynamic CMakeFiles/cmTC_2cc84.dir/testCCompiler.c.o  -o cmTC_2cc84 
    /usr/local/mipsisa32r2el/r23/lib/gcc/mipsisa32r2el-axis-linux-gnu/4.7.2/../../../../mipsisa32r2el-axis-linux-gnu/bin/ld: this linker was not configured to use sysroots
    collect2: error: …
Run Code Online (Sandbox Code Playgroud)

gcc mips cmake cross-compiling

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

计算稀疏矩阵上的Jaccard距离

我有一个大的稀疏矩阵 - 使用scipy的sparse.csr_matrix.值是二进制的.对于每一行,我需要计算相同矩阵中每行的Jaccard距离.最有效的方法是什么?即使对于10.000 x 10.000矩阵,我的运行时间也需要几分钟才能完成.

当前解决方案

def jaccard(a, b):
    intersection = float(len(set(a) & set(b)))
    union = float(len(set(a) | set(b)))
    return 1.0 - (intersection/union)

def regions(csr, p, epsilon):
    neighbors = []
    for index in range(len(csr.indptr)-1):
        if jaccard(p, csr.indices[csr.indptr[index]:csr.indptr[index+1]]) <= epsilon:
            neighbors.append(index)
    return neighbors
csr = scipy.sparse.csr_matrix("file")
regions(csr, 0.51) #this is called for every row
Run Code Online (Sandbox Code Playgroud)

python numpy scipy sparse-matrix

6
推荐指数
1
解决办法
4292
查看次数

基于F#continuation的尾递归

有人可以澄清acc ""在终止基于延续的尾递归函数时的需要,如下例所示:

let rec repeat_cont i s acc = 
if i = 0 then acc ""
else repeat_cont (i-1) s (fun x -> acc(s + x))

repeat_cont 4 "xo" id
val it : string = "abababab"
Run Code Online (Sandbox Code Playgroud)

如果结果是一个列表,它会是acc [],和acc 0为整数.

f# tail-recursion continuation-passing

5
推荐指数
2
解决办法
789
查看次数

Cmake Openssl not found

Want to cross-compile a C application that uses Azure IoT SDK, which unfortunately requires Cmake. Cmake refuses to build my toolchain because it claims that it cannot find Openssl that I've compiled for my target architecture.

I've tried adding OPENSSL_ROOT_DIR to the folder it's in.

SET(OPENSSL_ROOT_DIR /path/to/openssl)
Run Code Online (Sandbox Code Playgroud)

I continually get the error:

  Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
  system variable OPENSSL_ROOT_DIR (missing: OPENSSL_LIBRARIES) (found
  version "1.0.2g")
Run Code Online (Sandbox Code Playgroud)

我还尝试按照错误提示将系统变量设置为这些文件夹,但它似乎忽略了它们并提示相同的错误。我试过将它添加到与我的 C 编译器相同的文件夹中也无济于事。

我已经没有什么可以尝试的了,这一点我不明白为什么它不起作用。有什么建议?

openssl cmake cross-compiling

5
推荐指数
1
解决办法
8138
查看次数

F Sharp将元组列表转换为映射元组列表

声明一个将对列表转换为Relation的函数.

type Relation<'a,'b> = ('a * 'b list) list
Run Code Online (Sandbox Code Playgroud)

基本上,转这个:

[(2,"c");(1,"a");(2,"b")]
Run Code Online (Sandbox Code Playgroud)

进入这个:

[(2,["c";"b"]);(1,["a"])]
Run Code Online (Sandbox Code Playgroud)

以这种形式:

toRel:(’a*’b) list -> Rel<’a,’b> 
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?这不是家庭作业,只是自学,这个让我有点难过,考虑到形式不允许积累.

f# functional-programming

4
推荐指数
1
解决办法
579
查看次数

在C中复制strtok令牌的内容

需要分离一个字符串然后再进行另一次分离.

char *token = strtok(str, ",");
while(token){
    char *current_string = malloc(sizeof(char) * strlen(token));
    strcpy(current_string, token);

    char *tk = strtok(current_string, ":"); // KEY
    printf("key: %s ", tk);
    tk = strtok(0, ":");                    // VALUE
    printf("value: %s\r\n", tk);
    printf("%s\n", token);
    token = strtok(0, ",");
}

printf("Done\n");
Run Code Online (Sandbox Code Playgroud)

试图复制内容token,但这样做会混淆token变量中的内容.它只处理一行而不是它应该处理的三行.我怀疑问题是strcpy(current_string, token)但不确定我应该怎么做.

c delimiter strtok

4
推荐指数
1
解决办法
421
查看次数

扔进C#里面的Catch

昨天找到的东西让我意识到我很可能仍然缺少关于C#的基本花絮.

我有一个无状态服务结构应用程序.我在主循环中有一个尝试捕获.如果我在这个循环中抛出一个异常,它会跳出while循环并且服务有效地停止.如果我throw向catch子句添加一个,则服务将重新启动.

    protected override async Task RunAsync(CancellationToken cancellationToken)
    {
        try
        {
            long iterations = 0;
            while (true)
            {
                cancellationToken.ThrowIfCancellationRequested();

                await Task.Delay(TimeSpan.FromSeconds(3), cancellationToken).ConfigureAwait(false);

                // Do stuff...

                if (iterations > 4) {
                    throw new Exception();
                } 

                ServiceEventSource.Current.ServiceMessage(this.Context, $"Working-{++iterations}");
            }
        }
        catch (Exception ex)
        {
            // Log stuff...
            throw;
        }
    }
Run Code Online (Sandbox Code Playgroud)

有人可以解释为什么这是或指示我到哪里可以得到答案?我找不到任何可以解释这种行为的东西.

编辑:这不是重复是什么"投掷"和"投掷前"之间有什么区别?因为,据我所见,它没有解释我的问题,为什么函数再次运行.该主题更多的是解释之间的区别throwthrow new各自的堆栈跟踪.

c# throw rethrow

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

CMake 中 OpenSSL 加密的静态链接

我需要为 MIPS 设备制作一个交叉编译的 OpenSSL。我试过按照文档进行操作。设置OPENSSL_USE_STATIC_LIBS为 true 并设置target_link_libraries为您需要的库文件。

CMakeLists.txt:

compileAsC99()

if(NOT ${use_http})
    message(FATAL_ERROR "program being generated without HTTP support")
endif()

set(program_c_files
    ...
)

set(program_h_files
    ...
)

include_directories(...)

add_executable(program ${program_c_files} ${program_h_files})

set(OPENSSL_USE_STATIC_LIBS TRUE)
#target_link_libraries(program OpenSSL::Crypto)
target_link_libraries(program /home/program/mips/lib/libssl.so.1.1)
target_link_libraries(program /home/program/mips/lib/libcrypto.so.1.1)
Run Code Online (Sandbox Code Playgroud)

它编译得很好,没有警告,但检查生成的二进制文件告诉我它仍然是共享库。

readelf -d 程序:

Dynamic section at offset 0x1bc contains 35 entries:
  Tag        Type                         Name/Value
 0x00000001 (NEEDED)                     Shared library: [libssl.so.1.1]
 0x00000001 (NEEDED)                     Shared library: [libcrypto.so.1.1]
 0x0000000f (RPATH)                      Library rpath: [/home/program/mips/lib]
Run Code Online (Sandbox Code Playgroud)

我不明白我做错了什么。

编辑:已经看过在 CMake 中静态链接 OpenSSL 加密库,但它没有告诉我任何新的东西。

编辑 2:根据回复更新 …

openssl cmake static-linking

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