如何在 C 程序中使用 Boost 库

pul*_*_hh 4 c c++ gcc boost

我正在开发一个用 C 编写的项目,但我想使用 Boost。我已将 Boost 库包含在我的主文件中,如下所示:

#define GNU_SOURCE
#define _GNU_SOURCE
#include <stdlib.h>
#include "initialize.h"
#include <stdio.h>
#include <math.h>
#include <boost/random/linear_congruential.hpp>
Run Code Online (Sandbox Code Playgroud)

我正在编译gcc -W -Wall -I/usr/local/boost_1_76_0 main.c -o executable -lm -lboost_random

main.c:8:10: fatal error: iostream: No such file or directory
    8 | #include <iostream>
Run Code Online (Sandbox Code Playgroud)

我猜 Boost 库正在使用<iostream>,但由于它不是 C 库,我不知道如何处理这个问题......我应该用 C++ 编译吗?

dbu*_*ush 5

Boost 很大程度上是一个 C++ 库,因此不能在 C 程序中使用。

如果您想使用 Boost,则需要使用 C++。