Essentially, you have two tasks to complete:
- You must compile the fdlibm source to produce an object module suitable for your purpose.
- You must link the object module with your other object modules.
I see two issues with the first task. One, sources from projects like fdlibm are typically written to be portable to many systems and may involve a fair amount of work to configure. Rather than being very simple C or C++ code, they may use a number of preprocessor conditionals to select certain options, and the package the sources come in may have scripts to make various preparations for compiling.
Two, you want the sources to match the C++ standard’s specification for declaring sin
and cos
. If the fdlibm package you have supports C++, this might not require any work on your part. Otherwise, you may have to modify the sources to wrap the sin
and cos
definitions inside the std namespace, or otherwise modify the sources.
The second issue is linking. Using a library is not required. You can simply compile the source file(s) containing sin
and cos
to produce an object module (or modules), then link that object module (or modules) with your other object modules. If you wish, you can instead create a library, put the object module(s) with sin
and cos
into the library, and link the library with your object modules. With most common linkers, you can link a library with your object modules simply by listing it as input the linker, the same way object modules are listed. (Some linkers also have other options for referring to libraries, but simply giving its normal file path is usually sufficient.) You can create and link either a static or a dynamic library, as you prefer. If you use a dynamic library, it must be present when the executable runs. For a simple application for your own use, there is no need to use a dynamic library (or even to use a static library; object modules are fine). (Essentially, the purpose of libraries is to make distributing object modules to other people easier, or to organize large projects. Simple applications do not need libraries.)
Another note about linking: When you supply your own sin and cos, the linker has two implementations to choose from: Your implementations of sin and cos and the standard library implementations of sin and cos. Usually, standard libraries are linked in after any user-specified files, so merely specifying your object module or library will suffice to ensure your sin and cos are used, not the library’s sin and cos. In the event this is not the case, there should be linker options to change the order in which libraries are considered.