简体   繁体   中英

How do I use a Fresnel integral C Library in c++?

I've included a Fresnel Integral Library ( http://www.mymathlib.com/functions/fresnel_sin_cos_integrals.html ) in my c++ application.

Assume I have the following c++ code (main.cpp):

#include "include/Fresnel/fresnel_sine_integral.c"

using namespace std;

int main()
{
    return 0;
}  

But when I compile the program like this:

g++ main.cpp

I get the following error:

In function `xFresnel_Sine_Integral(long double)':
main.cpp:(.text+0x66): undefined reference to `xFresnel_Auxiliary_Cosine_Integral(long double)'
main.cpp:(.text+0x8d): undefined reference to `xFresnel_Auxiliary_Sine_Integral(long double)'
collect2: error: ld returned 1 exit status

Do I have to link the library on another way into my c++ application? Or do I have to compile on another way?

I think you'll need to make a library from the C source files you referenced. They aren't sufficiently self-contained as they are.

I would suggest structuring your build to compile the .c source files along with your own application sources, and linking the whole lot into an executable. You'll need to extract the function declarations from each of the .c files and put them into a .h header. You'd #include that header in your own source, and probably in the .c files unless you want a screen-full of compiler warnings each time you compile.

You'll need to decide whether to compile the .c files as ordinary C, or rename them and compile them as C++. You might have to modify them, for a C++ compiler to compile them without complaint. If you keep them as C, you'll need to arrange for these files to be compiled as C, and your own as C++. So the headers you make will need to be compatible with both C and C++ -- there are standard techniques for this, which I could advise on (but there's probably stuff on SO already).

If this were my problem to solve, I'd consider combining all the .c files into a single file, and fiddle it to be good C++ (probably not difficult). I'd create one single header from the declarations in the C source, suitable for including in C++ source (since it's all C++ now). However, I'm not sure whether the original files are licensed in such a way to allow this -- that's something I guess you'd need to check with the author.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM