V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
going2think
V2EX  ›  C++

如何使用 bazel 的 lib 文件中定义的类

  •  
  •   going2think · Jan 20, 2021 · 2199 views
    This topic created in 1927 days ago, the information mentioned may be changed or developed.

    大家好,有个问题请教下 我现在是有个类定义在 bazel 的 lib 中,想在 vs 里面调用,有什么方法吗,

    lib 类定义:

    // print_class.cpp
    
    #include <iostream>
    
    class PrintClass {
        public:
        void print_words() {
            std::cout << "============== this is the print===========" << std::endl;
        }
    };
    

    这个 cpp 文件通过 bazel 编译会得到一个 .lib 文件,后面希望调用这个.lib 文件来调用 PrintClass

    vs 里面调用代码

    // main.cpp
    
    // 如何通过.lib 文件引入 PrintClass??
    int main() {
        PrintClass pc = PrintClass();
        pc.print_words();
    }
    

    这里没法 include 上面的 print_class.cpp 文件,因为在 vs 里面编译通不过,只有通过 bazel 编译成 lib 来调用

    3 replies    2021-01-21 03:52:28 +08:00
    ai277014717
        1
    ai277014717  
       Jan 20, 2021
    提供 header 是代码可以通过编译。链接过程把.lib 链接进去。
    edimetia3d
        2
    edimetia3d  
       Jan 20, 2021
    java 转行的吗? C++不能这么用,关键词"头文件"
    neoblackcap
        3
    neoblackcap  
       Jan 21, 2021
    include 头文件即可实现外部库的引入。不过你要搞清楚这个库到底是 C++ 库还是 C 库。
    如果是 C++的,那么请将你的编译器保持在跟其库一样的版本,否则请自求多福
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2596 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 12:46 · PVG 20:46 · LAX 05:46 · JFK 08:46
    ♥ Do have faith in what you're doing.