如何在C 项目中包括在GitHub上托管的库?(新的C 用户 - 以前使用的语言与软件包管理器使用)
How to include libraries hosted on Github in a C++ project? (New C++ user - previously used language with package manager)
我想在C 项目中包括uwebsockets,我不清楚如何执行此操作。我已经用.so
依赖项编译了项目,在GitHub上列出的项目时,我仍然感到困惑。
特别:
- 在将其包含在我的项目中之前,是否需要对第三方存储库进行编译?
- 在源代码目录中将库存储在哪里?
- 如何将源代码与第三方库联系起来?
- 是否需要诸如CMAKE之类的工具?
事先表示歉意,如果这些问题显而易见或愚蠢,我来自带有软件包经理的语言,所以这对我来说是新的。
update
在GitHub存储库中的"入门"指令之后,在克隆存储库后,确保依赖项已安装并运行make
,请观察到以下输出:
dave@desktop:~/gitrepositories/uWebSockets$ make
make `(uname -s)`
make[1]: Entering directory '/home/dave/gitrepositories/uWebSockets'
g++ -std=c++11 -O3 -I src -shared -fPIC src/Extensions.cpp src/Group.cpp src/Networking.cpp src/Hub.cpp src/Node.cpp src/WebSocket.cpp src/HTTPSocket.cpp src/Socket.cpp src/Epoll.cpp -s -o libuWS.so
In file included from src/WebSocketProtocol.h:5:0,
from src/WebSocket.h:4,
from src/Group.h:4,
from src/Group.cpp:1:
src/Networking.h:7:30: fatal error: openssl/opensslv.h: No such file or directory
#include <openssl/opensslv.h>
^
compilation terminated.
In file included from src/Networking.cpp:1:0:
src/Networking.h:7:30: fatal error: openssl/opensslv.h: No such file or directory
#include <openssl/opensslv.h>
^
compilation terminated.
In file included from src/WebSocketProtocol.h:5:0,
from src/WebSocket.h:4,
from src/Group.h:4,
from src/Hub.h:4,
from src/Hub.cpp:1:
src/Networking.h:7:30: fatal error: openssl/opensslv.h: No such file or directory
#include <openssl/opensslv.h>
^
compilation terminated.
In file included from src/Socket.h:4:0,
from src/Node.h:4,
from src/Node.cpp:1:
src/Networking.h:7:30: fatal error: openssl/opensslv.h: No such file or directory
#include <openssl/opensslv.h>
^
compilation terminated.
In file included from src/WebSocketProtocol.h:5:0,
from src/WebSocket.h:4,
from src/WebSocket.cpp:1:
src/Networking.h:7:30: fatal error: openssl/opensslv.h: No such file or directory
#include <openssl/opensslv.h>
^
compilation terminated.
In file included from src/Socket.h:4:0,
from src/HTTPSocket.h:4,
from src/HTTPSocket.cpp:1:
src/Networking.h:7:30: fatal error: openssl/opensslv.h: No such file or directory
#include <openssl/opensslv.h>
^
compilation terminated.
In file included from src/Socket.h:4:0,
from src/Socket.cpp:1:
src/Networking.h:7:30: fatal error: openssl/opensslv.h: No such file or directory
#include <openssl/opensslv.h>
^
compilation terminated.
Makefile:8: recipe for target 'Linux' failed
make[1]: *** [Linux] Error 1
make[1]: Leaving directory '/home/dave/gitrepositories/uWebSockets'
Makefile:6: recipe for target 'default' failed
make: *** [default] Error 2
只是为了回答问题:
在将其包含在我的项目中之前,是否需要对第三方存储库进行编译?
是的,您必须以前编译库,因为没有图书馆就无法链接程序。
在源代码目录中将库存储在哪里?
make install
会照顾好这个。
如何将源代码与第三方库联系起来?
您不链接源代码,而是将对象文件与库一起链接以形成可执行文件。这看起来或多或少像
g++ -o sample main.o second.o more.o -L/path/to/libs -luWS -lmorelibs
是否需要诸如CMAKE之类的工具?
不是在这种情况下, uWebSockets
只使用make,别无其他。
错误消息是关于缺少标头文件的。这意味着,您必须为先决条件安装适当的开发人员包,即openssl和zlib。
对于debian/ubuntu,这是由
完成的sudo apt-get install libssl-dev zlib1g-dev
相关文章:
- C++如何通过用户输入删除列表元素
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何使用用户输入在C++中正确填充2D数组
- C++MySQL C api用户输入行
- 使用用户定义函数的字符串反转
- 用户定义函数中的指针和输入
- 为什么即使使用-cudart-static进行编译,库用户仍然需要链接到cuda运行时
- 如何只允许用户输入正整数
- C++如何计算用户输入的数字中的偶数位数
- 通过for循环使用用户输入填充列表
- 这是我尝试让用户将值输入到数组中.然后将其隐藏为大量的星号
- 在C++中,我如何接受不同于同一行的用户输入
- 当用户超过按钮点击限制时报告
- 是否可以用类似C/C++(或任何语言)的语言,从作为用户输入的字符串或文件中创建用户定义的数据类型
- C++程序中的首选用户语言
- 如何在C 项目中包括在GitHub上托管的库?(新的C 用户 - 以前使用的语言与软件包管理器使用)
- 如何在用户更改Windows中的语言键盘布局时得到通知
- 如何在OSX中使用c++获取当前用户的语言环境
- 用户界面 - 将 GUI 添加到C++软件的最佳语言
- 将用户定义的规则添加到现有语言