简体   繁体   English

初学者将Crd Lion与3rd Party C文件一起使用

[英]Using 3rd Party C files with C Lion, a beginner perspective

I am in despair for a simple explanation to a simple problem. 我对一个简单问题的简单解释感到绝望。
I made a program in java that I need to recode in C for performance reasons. 由于性能原因,我用Java编写了一个程序,需要用C重新编码。 So I learned how to program in C. The problem is that C standard libraries do not contain collections (why????) such as a hashtables, treesets, etc. So I found this: https://github.com/srdja/Collections-C . 因此,我学习了如何使用C进行编程。问题是C标准库不包含哈希表,树集等集合(为什么????)。所以我发现了这一点: https : //github.com/srdja / Collections-C

I use CLion on windows, I know well about coding but NOTHING about compiling, CMake, Linux, etc. My question is: I want to use those external source files my project, why is that so hard ? 我在Windows上使用CLion,我对编码非常了解,但对编译,CMake,Linux等一无所知。我的问题是:我想在项目中使用这些外部源文件,为什么这么难? The tutorial on the link provided above tells me to use Linux command lines and stuff that I don't understand. 上面提供的链接上的教程告诉我使用Linux命令行和我不了解的东西。 Online I find stuff about telling me to add commands into CMakelist, none of these work for diverse reasons. 在线上,我发现了一些有关告诉我将命令添加到CMakelist中的内容,但是由于种种原因,这些命令都不起作用。 I can't even copy all the .c and .h into my project because "they are not part of the project". 我什至无法将所有.c和.h复制到我的项目中,因为“它们不是项目的一部分”。 So can anyone tell me how to make this simple code work ? 那么谁能告诉我如何使这个简单的代码起作用?

#include <stdio.h>
#include "hashtable.h"
int main() {
    Hashtable *table;
    hashtable_new(&table); //this is a function that creates the new hashtable in the source code of Collections-C
    return 0;
}

By the way, because I think it's the same problem, how can I have subdirectories in my project so that I can put my header files away to keep the project tree tidy? 顺便说一句,因为我认为这是相同的问题,所以我该如何在项目中包含子目录,以便可以放置头文件以保持项目树整洁? I tried to add add_subdirectories($/include) to my CMakelist.txt 我试图将add_subdirectories($/include)到我的CMakelist.txt

I am expecting people telling me that there are many similar questions already, but none of those I found is clear to me. 我希望人们告诉我已经有很多类似的问题,但是我发现这些问题都不清晰。

Thank you if you have the patience to explain this to me. 谢谢您是否有耐心向我解释。

Henri 亨利

This is for C++, but it should work for your C code. 这是用于C ++,但它应适用于您的C代码。 In this example, it's defining where to find the OpenSSL and Google Test headers, and how to link with the Google Test library and the OpenSSL library (which is in C, as it turns out): 在此示例中,它定义了在哪里可以找到OpenSSL和Google Test标头,以及如何与Google Test库和OpenSSL库(事实证明,该库位于C中)链接:

cmake_minimum_required(VERSION 3.5)
project(stackexample)

set(CMAKE_CXX_STANDARD 11)
find_library(GTest required)
include_directories(${GTEST_INCLUDE_DIRS} /usr/include/openssl)

set(
    SOURCE_FILES
    StackExample.cpp
    StackExample.h
)

add_executable(stackexample ${SOURCE_FILES})

target_link_libraries(stackexample -lgtest -lssl -lcrypto pthread)

Collections-C appears to have an installer, so you would Collections-C似乎具有安装程序,因此您将

  • List the path to its installed headers in the include_directories line include_directories行中列出其已安装标头的路径
  • List its installed library in the target_link_libraries line target_link_libraries行中列出其已安装的库

The solution was to build the library then do stuff with CMake. 解决方案是先构建库,然后使用CMake进行处理。 I followed this tutorial. 我遵循了教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用正确的 dll 文件在 Cython C 扩展中启用第三方 C 库? - How do I use the correct dll files to enable 3rd party C libraries in a Cython C extension? C ++单元测试和存根第三方C库 - C++ Unit Testing and stubbing a 3rd party C library 与C一起使用第三方ADT(GLib,sys / queue.h等) - Using 3rd Party ADTs (GLib, sys/queue.h etc.) with C 在C语言中,如何添加第三方库并使用Makefile从我现有的代码库中调用 - In C, how to add 3rd party Libraries and call from my existing code base using Makefile 在不使用3rd party库的情况下基于C *中基于char *的多平台Unicode处理? - Multi-platform Unicode handling based on char* in C without using 3rd party libraries? Python努力创建一个包装第3方dll的C扩展 - Python Struggling to create an C extension wrapping a 3rd party dll Ruby C扩展无法在运行时解析第三方dll - Ruby C extension not resolving 3rd party dlls at runtime 分段错误:11,C的绝对入门指南,第三版Chapter6ex1.c - Segmentation fault: 11, Absolute Beginner's Guide to C, 3rd Edition Chapter6ex1.c 对使用开源第三方库感到困惑 - Confused in using opensource 3rd party libraries 按升序组合2个int文件,进行比较,然后将它们排序为第3个文件,而无需在c中使用数组 - Combining 2 files of ints in ascending order, comparing them, and then sorting them into a 3rd file without using arrays in c
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM