且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从一个不同的项目,在C ++中调用一个方法?

更新时间:2023-11-30 14:25:28

是的,C ++没有组件的概念存在于C#和.NET中。这使得像这样的任务稍微更困难,这是C ++直接编译为本地代码的事实。

Yeah, C++ doesn't have the notion of assemblies that exists in C# and .NET. It makes tasks like this slightly more difficult, a virtue of the fact that C++ compiles directly to native code.

相反,你通常在代码文件的顶部包含必要的头文件( *。h ),并指示链接器链接到相应的 .lib 文件。通过转到项目的属性,选择链接器 - >输入,并将文件添加到其他依赖关系部分,可以实现这一点。

Instead, you'll generally #include the necessary header files (*.h) at the top of your code file, and instruct the linker to link to the appropriate .lib file(s). Do that by going to your project's Properties, selecting Linker -> Input, and adding the file to the "Additional Dependencies" section.

code> .lib 文件,可以使用Visual Studio添加对其他项目的引用,如果它是同一个解决方案的一部分。 Microsoft在C ++中创建和使用动态链接库时有讲解这可能值得一读。

As an alternative to linking to the .lib file, you can use Visual Studio to add a reference to the other project, if it's part of the same solution. Microsoft has a walk-through on creating and using a dynamic link library in C++ that might be worth a read.