简体   繁体   English

如何访问第三方源文件中的功能?

[英]How do I access functions in a third party source file?

I was looking for an algorithm that would enable me to use the mathematical Bessel function for complex numbers. 我一直在寻找一种算法,使我能够对复数使用数学贝塞尔函数。 Now I have found a promising result . 现在我找到了可喜的结果 (I'm interested in Bessel functions Jv and Yv for real or complex arguments and real order .) (我对Bessel函数Jv和Yv的实数或复数实数和实数顺序感兴趣。)

I am working in Visual Studio 2010 Express C++ and now I want to get access to those functions implemented there. 我正在使用Visual Studio 2010 Express C ++,现在我想访问其中实现的那些功能。 How do I do that? 我怎么做?

Download this http://www.crbond.com/download/bessel.zip file and add the files to your visual studio project. 下载此http://www.crbond.com/download/bessel.zip文件,并将文件添加到Visual Studio项目中。 To use the functions, you will need to #include "BESSEL.h" to your source file. 要使用这些功能,您需要在源文件中#include "BESSEL.h"

I got it compile on Visual Studio by doing the following 我通过执行以下操作在Visual Studio上对其进行了编译

  1. Adding _USE_MATH_DEFINES to preprocessor definitions. _USE_MATH_DEFINES添加到预处理程序定义中。
  2. Changing #include <complex.h> to #include <complex> #include <complex.h>更改为#include <complex>
  3. Adding using namespace std; using namespace std;添加using namespace std; to BESSEL.H 前往BESSEL.H

Example of how to call a function: 如何调用函数的示例:

#include "BESSEL.H"
#include <iostream>

int main() {
    double x, i0, i1, k0, k1, i0p, i1p, k0p, k1p;
    x = 5.0;
    i0 = 1.0;
    i1 = 2.0;
    k0 = 3.0;
    k1 = 4.0;
    i0p = 5.0;
    i1p = 6.0;
    k0p = 7.0;
    k1p = 8.0;

    bessik01a(x, i0, i1, k0, k1, i0p, i1p, k0p, k1p);
    // Results are stored in the variables i0..k1p
    cout << i0 << " " << i1 << " " << k0 << " " << k1;
    return 0;
}

Add the files linked above to your project: 将上面链接的文件添加到您的项目中:

解

Note you have to edit out old header files in these .cpp files and .h file. 请注意,您必须在这些.cpp文件和.h文件中编辑掉旧的头文件。 More specific: change 更具体:变更

#include<complex.h>

to

#include<complex>

and use namespace std. 并使用命名空间std。 Also for math.h . 也适用于math.h In main.cpp as in picture above write: 在main.cpp中,如上图所示:

#include <iostream>
using namespace std;

#include "BESSEL.H"

int main ()
{
    complex<double> z = 3;
    complex<double>  J0;
    complex<double>  J1;
    complex<double>  Y0;
    complex<double>  Y1;
    complex<double> J0p;
    complex<double> J1p;
    complex<double> Y0p;
    complex<double> Y1p;

    cbessjy01(z,J0,J1,Y0,Y1,J0p,J1p,Y0p,Y1p);

    cout<< "J0:  " << J0  << "\n";
    cout<< "J0p: " << J0p << "\n";
    cout<< "J1:  " << J1  << "\n";
    cout<< "J1p: " << J1p << "\n";
    cout<< "Y0:  " << Y0  << "\n";
    cout<< "Y0p: " << Y0p << "\n";
    cout<< "Y1:  " << Y1  << "\n";
    cout<< "Y1p: " << Y1p << "\n";

    cin.get();
    return 0;
}

Try to run the program. 尝试运行该程序。 z is the argument for the bessel function. z是贝塞尔函数的参数。

You may ask what are J0 , J1 , etc they are the Bessel functions but if you need to detremine which is which try a numerical value in the formulas you have. 您可能会问什么是J0J1等,它们是Bessel函数,但是如果需要确定,这是您可以尝试的公式中的数值。 for example check J0 is the result of which formula. 例如,检查J0是哪个公式的结果。 I'm not an expert in Bessel functions. 我不是贝塞尔函数专家。 But if you give me the exact formulas you need to use I can test. 但是,如果您给我确切的公式,则可以测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Visual Studio C++ 中使用第三方 DLL 文件? - How do I use a third-party DLL file in Visual Studio C++? 如何将第三方库添加到QtCreator? - How do I go about adding a third party library to QtCreator? 如何在 cmake 中构建参数化的第三方库? - How do I build a parameterized third-party library in cmake? 如何从第三方框架和源代码创建框架? - How can i create a framework from a third party framework and my source code? 如何在CMake中访问源文件名? - How do I access the source file name in CMake? 如果我对头文件做了一些小改动,是否需要重新编译第三方库 - Do I need recompile third party libraries if I make a small change to the header file 如何查找和填充第三方源的Flash字段 - How to find and populate Flash fields of a third party source 如何抑制第三方源文件中的警告? - How to suppress warnings in third-party source files? 当我使用第三方库时,如何找出我需要链接的 lib 文件? - How to find out which lib file I need to link while I use a third party library? 如何在C ++中的线程中正确处理永久挂起的第三方库调用? - How do I correctly handle a permanently hung third-party library call in a thread in C++?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM