Cross-Project References in Visual Studio 2015 - visual-c++

I am trying to reference a dll project from another project, and am encountering a few difficulties. I have done the following:
Added both projects to a solution
Within my executable project, I add the dll project as a reference.
I add the include directory under Properties --> C/C++ --> Additional Include directories.
I thought this was sufficient - I don't get any errors, my intellisense is detecting the dll project and everything compiles. But when I run, I get the following system error messagebox:
The program can't start because xxx.dll is missing from your computer.
Try reinstalling the program to fix this problem.
So I have tried adding the directory where the dll and lib files are built to to Reference Directories and Library Directories under VC++ Directories in the properties, but still get the same error.

Related

Android-NDK: Unsatisfied Link Error : Cannot load library: soinfo_relocate: cannot locate symbol "tcgetattr"

I am building the app available at https://github.com/thibautd/android-serialport-api/tree/master/android-serialport-api/project using Android NDK.
What have I done until now:
Build the project using gradle version 'com.android.tools.build:gradle-experimental:0.7.0-alpha1'
I am building this on android-17 and running on Android device with 4.2. I have also tried android-19
Build goes through without any errors but at runtime I get the exception Cannot load library: soinfo_relocate: cannot locate symbol "tcgetattr"
I have tried several options to get this working but all of them fail
Options I have tried
Setting APP-PLATFORM like mentioned in Cannot locate symbol 'tcgetattr' referenced by "libcrypto.so"
Using $(PREBUILT_SHARED_LIBRARY) by including the .so file avialable in the same github location as mentioned in How can i Link prebuilt shared Library to Android NDK project?
Tried setting LOCAL_EXPORT_C_INCLUDES in both option 1) and 2) above as mentioned in the same post How can i Link prebuilt shared Library to Android NDK project?
Also tried option mentioned at Cannot load library: reloc_library[1285]: cannot locate 'rand'
Put all the required include files directly in the project under /jni and tried building the project.
My project compiles absolutely fine. When testing I have always deleted the contents in build folder and rebuilt the project. To make sure the .so files are indeed created properly.
In all the cases I end up in exactly the same error soinfo_relocate: cannot locate symbol "tcgetattr"
I think it is because of the fact that some of the includes like unistd.h are not correctly referenced in runtime but I am not able to figure out how to get this working.

Error while adding mp4parser library to a project in android studio

I'm trying to use mp4parser library in my project. My android studio version is 1.0.2. Here's what I've done so far:
I've downloaded mp4parser zipfile from the link: https://github.com/sannies/mp4parser
I've extracted the zip file to MyProjectName/app/libraries
Renamed the folder to mp4parser
Add this line of code to settings.gradle file:
include ':app:libraries:mp4parser'
Add this line of code to build.gradle (in dependencies block):
compile project('libraries:mp4parser')
Now I want to sync the project with gradle files. This error pops up:
Error:Configuration with name 'default' not found.
I don't have this problem with other libraries. Seems that its only mp4parser that I have problem with. How can I fix this?
If you're including the library as source, the best thing to do is to unpack it somewhere and import it as a module.
The error you're getting is cryptic but it means that the build system is looking for a build.gradle file at that location and not finding it (or it doesn't see an apply plugin statement in the file telling it what to do). I'm assuming that the library you're trying to use doesn't have a Gradle build script.
If you import the library using the Android Studio UI, a build script will be generated for the module and you should be good to go.

Building with dokan.lib

I have downloaded the Dokan Library 0.6.0 (used to write a file system in user mode).
I'm using VS 2013 and have created a project to build the sample called mirror.c. It uses a LIB called dokan.lib. It compiles just fine but the linker gives an error saying
"unresolved external symbol __imp__DokanMain#8". I dumped the lib and __imp__DokanMain#8 does exist within dokan.lib.
Under Properties->Linker->Additional Library Directories, I added "c:\Program Files (x86)\Dokan\DokanLibrary" but that didn't help. Then I changed that to "c:\Program Files (x86)\Dokan\DokanLibrary\dokan.lib" but that also didn't help.
I have read everything at the dokan web site but nothing talks about building with Visual Studio.
Does anyone have any ideas?
Please move "dokan.lib" from Settings -> Linker ->General -> Additional Library Directories. This is meant to include only the paths to the libraries. You can leave the path to the library in tact in there (i.e, C:\Program Files (x86)\Dokan\DokanLibrary).
Place the "dokan.lib" in Settings->Linker->Input->Additional Dependencies.

Visual C++ - cant see which external missing

I try to build my multiproject application in Visuas C++ 10 in release mode.
I get the next link error:
2> All outputs are up-to-date.
2>PidAppLib.lib(ThreadWin32.obj) : error LNK2011: precompiled object not linked in; image may not run
2>C:\infinite_memories_svn\projects\sw\NewPidTools\PidWriter\Release\PidLabler.exe : fatal error LNK1120: 1 unresolved externals
2>
2>Build FAILED.
How can I know which object unresolved?
ThreadWin32.obj is external lib which was downloaded from internet.
Ok.
I've solved the problem.
I have 2 libraries, let say a.lib and b.lib, and project, c.
a.lib uses b.lib so in librarian dependencies of a.lib I added b.lib, c uses a.lib so I added
it to dependencies.
It works in debug but in release I should also add b.lib to dependencies of c.
Strange but it solved the problem
I had this error in a large project I was refactoring. During the refactoring process I would occasionally compile individual source files to check changes I'd made without having to build the entire project. Depending on your project configuration this can result in .obj files being output in a different directory to where they would normally be output when you build the project. In my case the .obj files for source files compiled manually were output in the source code directory instead of the intermediate build directory.
A side-effect of this appeared to be that when building the whole project, source files that had been manually compiled might not be recompiled even if other changes elsewhere meant they should be (like a change that required recompiling the precompiled header file).
The solution for me was to manually delete all .obj files generated by manually compiling individual source files. Depending on project configuration executing Clean on the project might also work.

Android NDK java.lang.UnsatisfiedLinkError: findLibrary returned null

Having the above error in your Android JNI app? Read on...
Up front, I'll say that I've already solved this, in my own way, but I feel something in the Android build system (perhaps regarding Eclipse) is broke, and I hope to save someone else hours of pain. Perhaps others have come across this issue and can comment on what worked for them.
For a while, I've had an Android project with some JNI code that I developed using the NDK. Then, today, I changed something in the java code and then poof, I could no longer load my JNI library. It failed with an exception like:
E/AndroidRuntime( 999): java.lang.UnsatisfiedLinkError: Couldn't load mylibrary: findLibrary returned null
I googled and tried everything (rebuilding, close and relaunch Eclipse, etc, etc)
What finally fixed my problem? I physically uninstalled my app from the device before trying another run. That's it. After that, it worked. What worked for you?
If you have a native project with LOCAL_MODULE "libXYZ", make sure to load it as
System.loadLibrary("XYZ");
If you are trying to run your app in a simulator, then make sure that you have specified the correct architecture in Run -> Run Configurations -> Target (you may need to add the required simulator using Window -> Android Virtual Device Manager).
I had the same problem when trying to execute an app in an Intel simulator, while the app was using a library precompiled for the ARM.
I've got this issue too, but for my situation, i'm using my libs in another project. And I don't think it's a matter of eclipse or android-ndk.
you may check these tips that can lead to UnsatisfiedLinkError and it works fine for me, good luck :)
must following the JNI interface's nameing rule(you said that you did load the library successfully before, so you can ignore this) and the libraries must in directory /your project/libs/armeabi/
if you ensure the above things are done, then you must ensure that your generated libs are installed into your app.apk, otherwise it will still cannot find the lib and thorw you an error. to do this, you right click on your eclipse project name, and go into Build Path - Configure Build Path, on the left menu, choose Java Build Path, then click on the Order and Export tab on the right panel, checking the checkbox before your library name and click OK, then clean,rebuild and run you project, and your libs will be installed into app.apk, things are done.
EDIT:
in a word, UnsatisfiedLinkError are thrown if the library is not installed into your app.apk, so it cannot be linked sucessfully.
In my case, while making a System Application the issue was related to permissions. After putting the ".so" files into /system/lib/ or /system/vendor/lib/ directory, I modified the default allocated permissions 600 to 755. It worked well.
Inside libs folder, I create a new folder called armeabi-v7a, and copied the .so file from armeabi to the new folder. It solves the error.
I was having the same issue and these are some of the problems I had with my project:
Changing from System.load("hello-test"); into System.loadLibrary("hello-test");;
Changing the C function signature to JNIEXPORT jstring Java_com_example_testndk_TestNDK_funcNami(JNIEnv* env, jobject thiz): here you use Java_<java_package_name>_<java-class-name>_<function-name>;
Adding NDK path to local.properties, in my case ndk.dir=<my-path-to-ndk-directory>; and
Updating my build.gradle to also include within defaultConfig: ndk { moduleName "hello-test" }.
Package name: com.example.testndk
Java class name: TestNDK
C source name: hello-test.c
JNI directory location within the project structure: AndroidProjects/TestNDK/app/src/main/jni
IDE: Android Studio 0.8.1.
First, check you have the jni files inside you libs folder in eclipse or jniLibs folder in android studio. When you checkin in any svn, cross check to check in the .so files too.
My Scenario was when Building with Android studio.
When you are building in android studio, your library .so files or (jni) files should be inside the \src\main\jniLibs\armeabi***.so folder.
where as these files will be inside the \libs\armeabi***.so in eclipse.
When building using both eclipse and android studio, you have to modify your build.gradle file as
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
// Fixed Issue : "android studio java.lang.unsatisfiedlinkerror: couldn't load find library returned null"
// Cause : For android studio : The JNI files should be placed in the /src/main/jniLibs folder.
// Fix : Mapping the jniLibs 's source Directories with Lib's folder
jniLibs.srcDirs = ['libs']
}
Here I am building the project using both the android studio and the eclipse.
just had a similar problem.
Check out your /data/data/your.package.name/lib directory
When i ls in my package directory it currently displays:
lib -> /mismatched_uid/settings_10037/fs_1000
probably i accidently switched the sharedUserId and thus the library can't be accessed anymore.
None of the previous answers solved my problem, but this did: All along the problem was that a necessary subdirectory and file were not present. All I had in my libs folder was an armeabi folder containing the proper .so file, but there are supposed to be 3 others, each with a .so file in them. Not certain yet which of the other three (armeabi-v7a, mips, or x86) was the required one, but I do know that all three were automatically generated when I added the Application.mk file to the same folder as the Android.mk file, and made sure it had the following line in it:
APP_ABI := all
For me, that line is the only text in there. When ndk-build is then run the Application.mk file apparently causes "all" the 4 folders to be created and the proper .so files to be created in them. Once I got Application.mk in place, I ran ndk-build again, and then did a clean and a clear on my Eclipse project before trying again. Everything ran perfectly.
No need to root the device..deploy app on emulator and browse the folder
If you have a native project with "libXYZ.so", make sure that /system/lib/libXYZ.so does not exist on your device. There is a painful workaround: use
System.load("/data/data/your.package.name/lib/libXY.so")
instead of System.loadLibrary().
I just had this happen and the problem was that the device simply did not have enough space to install the library. I uninstalled some other apps and then it worked.
Had identical problem.
Just cleaned project and it worked. Mystery..
UnsatisfiedLinkerror is solved by this.Build your .so file again by "ndk_build"
I added
extern "C"
before functions declare
ex:
extern "C"
jstring
Java_lara_myapplication_MainActivity_stringFromJNI(
JNIEnv *env,
jobject /* this */) {
std::string hello = "Hello from C++";
return env->NewStringUTF(hello.c_str());
}
then the error was gone
Add this following code inside your gradle file
//libs is the location of your library's folder, It varies in diffarent projects like src/main/libs etc.
android {
sourceSets.main {
jniLibs.srcDir 'libs'
}
}
So, Android Studio keep on looking native libs inside jniLibs folder. this code will change the path of android studio to look libs in libs folder
In my case .so library is loaded correctly, but can not find method like below:
Caused by: java.lang.UnsatisfiedLinkError: Native method not found...
After hours of searching what can be problem noticed that application throws related error only for production flavor. Yes, we use proguard to obfuscate source code and it breaks .so library handler class... After adding below lines into proguard rules file. It started working as expected.
-keepclasseswithmembers,allowshrinking,allowoptimization class com.zk.android.jni.Device {
native <methods>; }
So if you use proguard and having similar problem with mine. Please check proguard file...

Resources