[英]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似乎具有安装程序,因此您将
include_directories
line 在include_directories
行中列出其已安装标头的路径 target_link_libraries
line 在target_link_libraries
行中列出其已安装的库
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.