如何从一个不同的项目,在C ++中调用一个方法? [英] How can you Call a method from a diffrent Project, both in C++?

查看:229
本文介绍了如何从一个不同的项目,在C ++中调用一个方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常在c#中工作,所以c ++中的某些东西让我困惑(他们看起来很不同,但名字几乎一样)

I'm normally working in c# so certain things in c++ keep confusing me alot (they seem so diffrent yet the names almost the same)

我创建了一个控制台项目中,我想运行一个不同的项目进行测试。我添加了项目作为控制台应用程序的参考,然后得到了卡住。

I created a Console project in which i want to run a diffrent project for testing purposes. i added the project as a reference to the console app, and then got kinda stuck.

在项目中没有命名空间,所以我不能做一个使用和如果我试图包括其他文件,它不能找到它(我想避免无法调试通过它所有)。

there is no namespace in the projects, so i can't do a using and if i try to include the other file, it cannot find it (and i want to avoid being unable to debug through it all).

类的代码可以找到这里(忽略c#部分),控制台

the code for the class can be found here(ignore the c# part), the console is just a standard console with nothing in it yet.

推荐答案

是的,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.

这篇关于如何从一个不同的项目,在C ++中调用一个方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆