emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.76k stars 3.3k forks source link

Compile the libraries error #19021

Open ShuoShenDe opened 1 year ago

ShuoShenDe commented 1 year ago

Hello guys, I want to compile a c++ file and use it in my web project. The file looks like

#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/filters/statistical_outlier_removal.h>
int main() {
    // 读入点云
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
    pcl::io::loadPCDFile("table_scene_lms400.pcd", *cloud);

    // 降采样
    pcl::VoxelGrid<pcl::PointXYZ> sor;
    sor.setInputCloud(cloud);
    sor.setLeafSize(0.1f, 0.1f, 0.1f);
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZ>);
    sor.filter(*cloud_filtered);
    // 平滑处理
    pcl::StatisticalOutlierRemoval<pcl::PointXYZ> sor2;
    sor2.setInputCloud(cloud_filtered);
    sor2.setMeanK(50);
    sor2.setStddevMulThresh(1.0);
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_smoothed(new pcl::PointCloud<pcl::PointXYZ>);
    sor2.filter(*cloud_smoothed);
    // 将处理后的点云保存为PCD文件
    pcl::io::savePCDFile("output.pcd", *cloud_smoothed);
    std::cout << "savePCDFile to output.pcd"; 
    return 0;
}

The only library I included is pcl I can compile it by the command:

g++ -o hello hello.cpp -I/usr/include/pcl-1.8 -I/usr/include/eigen3 -L/usr/lib/x86_64-linux-gnu -lboost_system -lpcl_io -lpcl_common -lpcl_filters

Version of emscripten/emsdk: Please include the output emcc -v here

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.34 (57b21b8fdcbe3ebb523178b79465254668eab408)
clang version 17.0.0 (https://github.com/llvm/llvm-project a031f72187ce495b9faa4ccf99b1e901a3872f4b)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /home/ubuntu/Documents/EBS1/Shen/emsdk/upstream/bin

Failing command line in full: I saw the tutorial, it should have to compile the library first, then I try to compile the pcl library, but they don't have the configure file. Is there any possible to generate configure file or any other way to compile the project use the CMAKELIST.txt?

Full link command and output with -v appended: the pcl lib

sbc100 commented 1 year ago

Yes, you can compile cmake-based projects using emscripten. The simplest way is to run emcmake cmake path/to/project.