vs2010 dll linking without a reference - visual-studio-2010

I have a project. That project references a .dll (d1). That .dll uses objects from another .dll (d2). I added a reference to d1 to the project, d2 is not referenced. Would it build?
If it builds would that mean that d2 is not used by d1? (so the above statement is wrong, d1 doesn't use any object of d2)
Please don't downvote, i'm sure that it is not possible - from where should the linker get the library if it's not referenced in the project, it is not even on the hard drive. And if it is possible just tell me how.

The dependencies of your dependencies are not required for your project to build. They are required for it to run, though. Your project only needs to know what d1 provides. When the project is run, d1 is loaded, and it should then try to load d2.

Check the below links:
Visual Studio 2010 not autolinking static libraries from projects that are dependencies as it should be supposed to
http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/bcfd6cd1-0fcf-4238-be93-59162e5d8230/
https://connect.microsoft.com/VisualStudio/feedback/details/638534/unresolved-externals-when-build-a-vc-project-with-chained-static-lib-dependencies#details
http://blogs.msdn.com/b/vcblog/archive/2010/05/03/flexible-project-to-project-references.aspx

Related

Xamarin binding library combination of InputJar and ReferenceJar?

I am trying to use https://github.com/Redth/Xamarin.Android.Xposed in Xamarin but the final result is rejected by Xposed, saying: "cannot load module" .. "the xposed api classes are compiled into the module's apk". The xposed-api.jar file is currently a EmbeddedJar, which is what causes that error. The xposed-api.jar file is made available during run-time by Xposed already.
From the xamarin docs.
InputJar – Does not embed the .jar into the resulting Bindings Library .DLL. Your Bindings Library .DLL will have a dependency on this .jar at runtime.
InputJar seems like it will solve my issue with it being compiled into the resulting apk. However, it can't compile into an apk at all. It gives me errors in the generated java file such as.
JAVAC0000: error: package de.robv.android.xposed does not exist
de.robv.android.xposed.IXposedHookLoadPackage 0
Then for ReferenceJar..
ReferenceJar – Specifies a reference .jar: a reference .jar is a .jar that one of your bound .jar or .AAR files depends on. This reference .jar is used only to satisfy compile-time dependencies. When you use this build action, C# bindings are not created for the reference .jar and it is not embedded in the resulting Bindings Library .DLL.
Great, it will provide it during compile-time.. however, no bindings will be generated so I can't use it.
I also tried combining these by creating 2 identical libraries with one having InputJar and the other ReferenceJar, but that did not work at all.
How can I achieve what I am trying to do?
To sum it up, I need to add xposed-api.jar as a library just like how android.jar of the Android framework is added. You can use the classes and compile properly, without the classes being compiled into the apk.
OK, The trick is actually "AndroidExternalJavaLibrary".
Imagine you have a Jar binding project XPosedAPI, and an Android project XposedSample.
The structure would be:
XPosedAPI
|-- Jar
|-- api-82.jar (InputJar)
XposedSample
|-- Jar
|-- api-82.jar (AndroidExternalJavaLibrary)
You see, the trick is you have to put the same jar file for each project.
For the Jar binding project, it has to be "InputJar" - that's used to generate the C# binding dll.
For the project that using the Jar bindng dll, the jar has to be "AndroidExternalJavaLibrary". This ensures the javac compile process.
There was an easier way, the Java.Interop.DoNotPackageAttribute.
You just put the below line on one of these projects (just put it on XPosedAPI project would be enough), and it works:
[assembly: Java.Interop.DoNotPackage("api-82.jar")]
However, this attribute is marked as "deprecated", although it's easier.
I figured out this, because I'm trying to do the same thing - write a xposed module in C#.
The Xamarin.Android.Xposed project looks nice, but in fact it won't work, and there are much more problems to be fixed besides the jar binding issue.
I think I'm getting closer, and I may publish it in a few days if I can fix all the bugs remained.
If you're interested, watch my project: https://github.com/UlyssesWu/XamarinPosed

adding reference to native visual c++ project

I have two visual c++ projects in my solution. First one (lets call it Main) is native code. The second one (Test), has Main added as reference. Test contains unit tests to methods in Main.
When I add Main as a reference to Test and try to compile it - I get errors that the library could not be found. Does adding a project as reference , does not add the output target path of Main to the library directories of Test ?
I don't know what VC is exactly doing under the hood, but adding reference to a project doesn't seem to have effect of linking libraries unlike C#.
You can use the code from another project by including and linking via the usual method of c++.

"always rebuild" due to C++/CLI referencing COM in same solution

I have a problem similar to VS2010 always thinks project is out of date but nothing has changed (I'm also on VS 2010):
I Enabled C++ project system logging which told me that:
00000727 29.93245506 [5864] Project 'C:\foo.vcxproj'
not up to date because 'C:\foo\INTEROP\INTEROP.bar.1.0.DLL'
was modified at 01/22/2014 11:02:49,
which is newer than 'C:\foo\RELEASE\METAGEN.WRITE.1.TLOG'
which was modified at 01/22/2014 16:02:30.
This is apparently telling me that foo project must be rebuilt because either bar.dll or the interop have changed.
foo is a C++/CLI project.
bar is a COM DLL.
foo has bar.dll as one of it's references.
I haven't rebuilt bar.dll (date for the dll file is yesterday).
I haven't modified any settings in project foo (to affect interop).
My question is: Why is Visual Studio deciding the interop is out of date and triggering a re-build on every single run of the application?
Note: This is a web application. foo is directly referenced from the web. bar is not directly referenced by the web.
EDIT:
I've created a simple look-alike solution with just 4 projects (2 for COM, website, and C++/CLI assembly). It seems the C++/CLI assembly always updates the INTEROP.bar.*.DLL file every time any build is triggered. This doesn't seem to be the case in the solution having problems.
This was my mis-understanding: I thought the interop DLL should only be updated if 1) the reference is re-added. 2) The COM object being referenced (possibly just the API) changed.
Apparently, interop.dll is updated every build of caller.
Finally this wording is extremely confusing to me and seems incorrect:
A was modified at 11:02:49, which is newer than B which was modified
at 16:02:30.
How could something from 11:02 be "newer than" something from 16:02? (almost feels like a backwards >= / <= check)
PS - I'm not adding the example solution here, because it doesn't fail like the real solution does.
Sorry for the confusion. It looks like I was leaving out one level of indirection in the dependencies. The chain was: ASP.NET Website -> C++/CLI Assembly -> COM DLL -> C/C++ Native DLL. All in a single solution.
We ended up refactoring to move all the COM DLL code into the C++/CLI Assembly changing it to merely: Web -> C++/CLI Assembly -> C/C++ Native DLL. At this point the problem went away.
It's not a very satisfying answer, but I don't have enough spare cycles to really dig into it now that it's no longer causing trouble.

Linking static libraries, that share another static library

I currently have a single Xcode project for a very large code base, I'll call it Project X, which I am dividing into a bunch of sub projects ( Projects A, B, C ).
So far, each of these projects compiles, on their own, just fine. They all produce static libraries. Project B and Project C are dependent on the static library produced by Project A in order to build.
I have another xcode project, Project Z, that requires the static libraries produced by Projects B and C. Herein lies the problem. When Project Z enters the linker phase, things blow up - duplicate symbols are found within the libs for Projects B and C for the code they originally linked against in Project A!
I'm pretty new to the world of static libraries, and I'm unsure of how to move forward with Project Z, or how to modify the other projects so that they are linking against the same Project A lib. I have a feeling it's not possible. What are my options here?
Edit:
I should clarify that Project B and Project C need to build into separate static libs because some clients will only require one or the other.
Also, I'm having this dilemma on both OSX and iOS platforms.
I realize that I could solve this problem on OSX by building the projects as dynamic libraries. However, I'd prefer not to do this, and it still leaves me with same issue on iOS.
Static libraries should never include other static libraries (or third party code in general). A static library is just a bundle of .o files glued together. So if you have multiple copies of the same information, it's going to blow up.
Each static library should just have its own code in it. The final application is responsible for linking all the required libraries together (including libraries required by libraries). This way there is exactly one copy of each thing linked.
This sounds like exactly the sort of problem CoacoaPods was created to solve. If you define pods for each of theses projects then Z should be able to determine and link against all of its dependencies all the way up the chain without introducing duplicate symbols.

Makefiles in Microsoft Visual Studio 2010

I am getting some linking errors during the compilation of C project in Microsoft Visual Studio 2010.I am getting the following errors:
error LNK2019: unresolved external symbol _CreateRelation referenced in function _main
The CreateRelation is one of the functions in my project. Following are my questions:
I think it is some dependencies problem.How would I set those dependencies rule in the IDE?
could you please tell me, is it always possible to build a project and set the linking rule, how much it is larger, without using makefile?
[EDIT]
relation.h
void createRelation(LIST);
mainfile.c
#include relation.h
#include xyz.h
.
.
.
int main(){
LIST Relation1;
some codes //
createRelation(Relation1);
some code //
}
The function creatRelation() is defined in the realation.h.
EDIT 2
In the function containing main
There are a few ways to set the dependencies for the build process.
If the code you are referencing is in a sub-project you can simply tell VS the build-dependencies. You do that by right-clicking on the project and select project dependencies. Then you can check all projects that should be built before this project is being built.
Another nifty feature of VS2010 are Property Sheets. In older versions of VS you had to tell the compiler the include path and the lib-path for every project. Now you can create property sheets for every library you are using and then simply adding them to your project. This way you only have to create a property sheet once and can use it in many projects.
So if the code is in another project that is not a sub-project you have to set the lib-path and include-path via those property sheets. You can display the property sheets used by your project by clicking View->Additional Windows->Property Manager
If you are not referencing to any external projects. This problem is most likely caused by you not implementing a function you declared. So the compiler knows about the function-prototype and doesn't complain but the linker can't find an implementation of the symbol.
I hope that helps
-- edit --
Since you said that the implementation is in the same file as the main-function I would suspect that the signature of the declared and defined function do not match. Are you getting any warnings about implicit function declaration?
Is that a copy-paste error?
CreateRealtion(x); vs. CreateRelation(x);

Resources