I have been given a static library(.a) by my client for my project. The objective of this static library is to integrate the functionality present in the library to my project.
The problem I'm facing is that when I'm trying to link this file, my linker could not link it and throws error.
Eg: consider the library has a function defined "void get_input ()". When I trying to invoke this function in my c file, my linker throws the error that the symbol is undefined.
I'm using Greenhills compiler.
Related
I have a C static library (foo.a) built for arm64 target (aarch64-unknown-linux-musl). I need to call some C functions in that library from my Rust project.
How do I link to that pre-existing library (foo.a) without building it?
I defined extern C functions for my library so technically, if I can link to it, I should be able to use it from Rust code?
extern "C" {
pub fn somefunc();
}
The problem I run into is that Cargo rust build wants to use the default toolchain (stable-x86_64-unknown-linux-gnu) and I don't have my library compiled for that target. Can I customize Cargo build to not require stable-x86_64-unknown-linux-gnuand simply link against existing pre-compiled library for another target platform?
I tried modifying rust project settings to change default rustup default <toolchain>; but cargo build did not recognize the target aarch64-unknown-linux-musl. Then I tried to change build dependency to specify foo.a as static lib for my target.
[build-dependencies]
foo = { artifact = "staticlib", version = "1.0", target = "aarch64-unknown-linux-musl" }
I have a static library for a Vector implementation in C.
I am now making a new library that is going to rely on the Vector in order to function property. This new library is called String. Both are static libraries created in Visual Studio with their own .c and .h files.
I do the following just like I would when referencing any other static library
Create new static library. Create .c and .h files in it.
project -> properties -> C/C++ -> Additional include directories and set as the folder that contains the .c and .h files for my Vector
File -> Add -> Existing Project and set the .vcxproj file of the Vector project.
In my solution explorer, I went under my String solution and right clicked References and then check-marked the Vector box that shows up.
At this point, my String is now correctly able to see Vector.
The problem
When I open a new project, repeat those same steps except with String as the target library, I get the following error:
Severity Code Description Project File Line Suppression State
Error MSB8006 The Platform for project 'C-DataStructuresLib.vcxproj' is invalid. Platform='HPD'. This error may also appear if some other project is trying to follow a project-to-project reference to this project, this project has been unloaded or is not included in the solution, and the referencing project does not build using the same or an equivalent Platform. CStringLib C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.InvalidPlatform.Targets 21
The line:
This error may also appear if some other project is trying to follow a project-to-project reference to this project, this project has been unloaded or is not included in the solution, and the referencing project does not build using the same or an equivalent Platform
Is correct because that's exactly what I'm trying to do. How can this be fixed?
Are you trying to compile as 64-bit project?
Check in the property page the section: Linker -> Advanced -> Target Machine
I'm trying to compile an old project in Borland C++ Builder 4. I have a working exe and the source files for that, therefore someone must have managed to compile it earlier. However, when I open the project, check if the project hs all the necessary files in the resources and try to compile it, I keep getting the following linker error:
[Linker Error] Unresolved external '_fastcall TMapperForm::Button1Click(System::TObject*)' referenced from ...\Unit1.obj
I can see that it cannot find an object in the library but I am not sure how to resolve it, because the obj file with the same name as the main cpp file is in the same file as the other files of the project and seems fine.
I have looked through the answers provided here for similar linker errors but none of what these have suggested worked for me. I have already tried the following:
Adding the .obj file to the Project Resources.
Trying to add pragma lines manually such as #pragma link (Unit1.obj)
Making sure that in Project>Options>Directories the right Include and Library paths were selected.
Checking if all the packages have been added.
None of this seems to work. I am fairly new to C++ and C++ Builder, so I am hoping that it is something trivial.
Has anybody seen this particular error?
The error was caused by a missing handler or more precisely a handler containing nothing.
While the handler for the button contained nothing, the TMapperForm class still included the definitions for an extra button named Button1 but it was not used. Commenting out the method and the declaration in the TMapperForm class (in the header file for Unit1) along with the handler in the C++ file resolved the problem.
I am building some test cases for a library. There a function is declared and used throughout the library. lib.a.
I then built up some test cases and implemented those functions, which are not declared in that library in a executable tests.exe
When I build test.exe it gives the error "Undefined reference to ....." How do I link correctly, I am using Eclipse and CppUnit. I have linked to the .a library and that .a library is building fine, I just can't link the two.
I’m cross compiling my C projects using Eclipse CDT/CodeSourcery Lite on Ubuntu v12.10.
In Eclipse CDT, I have these three C projects:
exeTop // executable that uses functions defined in libmiddle.a
libmiddle.a // static library that uses functions defined in libbottom.a
libbottom.a // standalone static library that doesn’t
depend on any other libraries
In order to build libmiddle.a, I have to copy libbottom.a into libmiddle’s project folder (see instructions here), which makes sense as libmiddle.a depends on libbottom.a.
However when building exeTop, I not only have to link to libmiddle.a but to libbottom.a (which libmiddle.a has already linked to).
Q1. Why is it required to link to libbottom.a from exeTop?
Q2. Are there any compiler or linker options I can use so that I can just link to libmiddle.a from exeTop?
You say "In order to build libmiddle.a, I have to link to libbottom.a, which makes sense as libmiddle.a depends on libbottom.a." I do not think this is the case at all. In fact, libmiddle.a can't really link against libbottom.a, because that's not how static libraries work on Linux. Static libraries are just "archives" of object files, and don't have a feature that makes them depend on other static libraries. Nor is it typical to stuff a static dependency into a static library itself.
For some more details, see [UNIX] : Do I need to add all libraries in my project's makefile, that are used from a library, used in my project?