JNI LibTorrent Cannot Load Library - java-native-interface

I want to develop a desktop application using libtorrent(libtorrent-rasterbar-0.16.15) library. The application is written in Java, so I want to use JNI to load the torrent.dll.
First I generated a .h file from javah. Then I wrote a .cpp file for it. Here comes the problem:when I add a line
static libtorrent::session gSession;
Compilation to dll works well and I got the .dll file. However, when I try to load this torrent.dll in Java through JNI. My application stuck there, without any error. When I remove that line and make the functions just print a few lines, it works.
I got my torrent.dll by bjam:
bjam msvc boost=source link=shared boost-link=shared runtime-link=shared
bjam version is 1.55.0

Related

Is there anyway to copy linked libraries directly into the executable?

I have a C++ project I'm compiling with CMake. One of the dependencies is LevelDB which I have installed using homebrew. In my CMakeLists.txt I have the following line:
target_link_libraries(test /usr/local/Cellar/leveldb/1.23/lib/libleveldb.dylib)
The binary that is generated works fine on my computer but it crashes when I run it on a computer that does not have libleveldb installed, stating that the library could not be found.
Is there any way that I could simply bundle the leveldb .dylib file into the executable itself -- this seems like the most reasonable way of making a binary that is simple for the end user to download and run.

Linking boost library in node native module, object file requiring alternative library version

I recently had the need to pull in the Boost Graph Library for one of the native node modules that I work on, along with boost serialization. There is a separate VS project that I do all of my development and testing for this module. The project compiles, links, and works as expected when run from the VS project.
I am having issues when I try to link the static serialization library with my module when building with node-gyp. I have included the full path to the serialization library in the libraries section of the binding.gyp file. In the object file produced from the node-gyp compiled file, the following line is causing a linker failure:
/FAILIFMISMATCH:"_CRT_STDIO_ISO_WIDE_SPECIFIERS=0"^#^Dlibboost_serialization-vc140-mt-s-x64-1_67.lib^#^Dlibboost_serialization-vc140-mt-s-x64-1_67.lib^#^Duuid.lib^#^Duuid.lib^#
The object file is expecting libboost_serialization-vc140-mt-s-x64-1_67.lib. When the build process tries to link the file, the linker spits out an error:
LINK : fatal error LNK1104: cannot open file 'libboost_serialization-vc140-mt-s-x64-1_67.lib'
However, boost built libboost_serialization-vc141-mt-s-x64-1_67.lib which is a different version than what the object file is expecting. I have tried to build the version that the object file is looking for, but I cannot seem to get boost to do so (each time I try, it skips all of the targets, even though I am specifying an alternative toolset).
How can I change the library version that the object file is expecting?
When I tried to build the "right" version of the serialization library, I had been using toolset=msvc-140. It should have been toolset=msvc-14.0. Sometimes I am dumb.

Qt 3rd Party Library Static Linking (QtSerialPort)

Turns out static linking was working, but only for Qt libraries. My 3rd party library QtSerialPort is not linking statically. After some reasearch, I've found that I either have to build this library statically or I have to link directly to a .pri file in my .pro file.
I'm not sure how to do either since it seems QtSerialPort has not been designed for static linking.
The .pri method I really don't understand and has been vaguely described in these two links:
http://qt-project.org/forums/viewthread/15223
http://www.qtcentre.org/archive/index.php/t-54505.html
Does anyone have any adivce on how to get either of these methods to work? Or possibly another method?
Also, MSVCP100.dll is not linking statically if anyone could give me any advice on that.
==================================================================================
I am trying to get Qt to statically link libraries so that I can make a standalone application. I have followed various tutorials on how to build Qt statically then building a static application but I am not having much luck. I believe I have succesfully built Qt with static linking because the application has grown in size from 79KB to 7+MB but I am still getting errors saying QtCore4.dll and QtSerialPort.dll are missing. Also, another issue I'm having when using this static configuration, which isn't too serious, is that when I close my program Windows thinks it has crashed and gives me a window saying MyProgram.exe has stopped working...
I am on a Windows machine using MSVC 2010 with Qt 4.8.5 and am using the third party library QtSerialPort.
What I've done accoring to the guides I've been reading is:
Download and extract qt-everywhere-opensource-src-4.8.5.zip
Open /mkspec/mwin32-msvc2010/qmake.conf and change the follwing lines to
CONFIG += qt warn_on release incremental flat link_prl precompile_header autogen_precompile_source copy_dir_files debug_and_release debug_and_release_target
and
QMAKE_CLFAGS_RELEASE = -O2 -MT
I then open the MSVC2010 command prompt and cd to this . I then enter the commands
configure -static -release -platform win32-msvc2010
nmake sub-src
After this is done I open my project and add
CONFIG += static
to the .pro file. In QtCreator I then go into Projects, Manage Kits then to Qt Versions and browse to the qMake I just generated. I add a new Kit with this version of qMake. I then clean all and switch to this new kit and run qmake from QtCreator. I then use msvc2010 command prompt to go to the directory where the files are generated and then
nmake release
This generates a rather large .exe but like I said, it's still depending on a couple .dll's.
For static linking of external library one have a couple options, both have their pros and cons.
I. Compile the library for static linking yourself. Link to it.
Look for possible existing configuration switches for static linking. There can be something like QTSERIALPORT_STATIC = no, etc. in the library's .pro/.pri files. Just say yes for the library to compile for static linking and go to the step 4!
In .pro/.pri file replace CONFIG += dll with CONFIG += static.
Remove export declarations from the library. Typically Qt library symbols are declared with some definition like QTSERIALPORT_EXPORT which expands to Q_DECL_EXPORT/Q_DECL_IMPORT in shared library build / its header files usage when linking. You'll need to find where this QTSERIALPORT_EXPORT is defined and replace it with empty definition:
#define QTSERIALPORT_EXPORT // in source file
or
DEFINES += QTSERIALPORT_EXPORT # in .pro/.pri file
Build the library.
Link to the library .lib/.a file, use the library header files for symbol declarations in your project.
II. Include the library source files into your project and compile them within it (no linking at all).
Include all the source files of the library into your project (add to SOURCES in qmake project file)
Determine all the stuff the library depends on (other libraries, Qt options, etc.) and include it also into your .pro file.
OR
Include the proper .pri file into your .pro if the library author provides it for in-project compilation (i.e. include(QtSerialPort.pri) or something.)
Remove export/import declarations from the library source code — as described in the item 3 of part I.
Build your project.

Why is my program trying to use libluajit-5.1.so.2 instead of libluajit.so?

I have a project I'm writing that uses LuaJIT. I'm trying to run my project on a computer I have not run it on in a while. It used to run just fine but now when I try to run it it complains.
I have LuaJIT in my source tree, and it builds just fine. I'm using CMake to generate my make files, and as far as I can tell CMake finds the file libluajit.so, but when I run my program, I get the following error:
../build/game/game: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory
I don't know why it's looking for that version of the library instead of libluajit.so. This is Ubuntu linux for what it's worth. I can add more details if necessary, I can add more details if necessary, I'm not sure what info would be helpful to figure out happening.
Edit:
To build and link the program I have these lines in the file CMakeLists.txt (this is abbreviated a bit to just show the relevant bits)
find_package(LuaJIT REQUIRED)
set(Extern_LIBS luajit)
add_executable(proj ${proj_Sources})
target_link_libraries(proj ${Extern_LIBS})
After I run cmake on my source directory, I run make. Then to run it I just run ./proj
When you built it, the ".so" was actually a symlink to the library. Verisioned filenames and SONAMEs are used so that multiple versions of a library can coexist, preventing problems commonly found on... other operating systems whereby older software is incompatible with the newer library, and newer software is incompatible with the older library.

My program can not find the boost library

I tried to write code that was a sample of the Boost test library:
#include <boost/unit_test.hpp>
BOOST_AUTO_TEST_CASE(test)
{
BOOST_CHECK(true);
}
I built the source code, and I got the execution file test.exe. I tried to execute that file, but I got an error message.
The program can't start because boost_unit_test_framework-vc80-mt-1_44.dll is missing from your computer. Try reinstalling the program to fix this problem.
But, I have ready that file on my boost library directory.
What's the problem in this case?
Background:
For my build environment, I use Windows 7 Ultimate x64, and Visual Studio 2005.
So I built boost library by my self, and I got all the libraries for the 64-bit computing system.
Using bjam, and I use the command: bjam --toolset=mvsc-8.0 address-model=64 threading=multi --build-system=complete install on 64-bit command prompt window.
After the build, I set the boost library and header directory in Visual Studio directory path option.
Thank you all!
Make sure that the path to your DLL is included in the "PATH" environment variable. (Or include the DLL in your exe directory if you like). That way the DLL will be found.
You can also choose to use the static versions of the Boost libraries.
Build or download the static libraries and point Visual Studio at those instead. The Boost code will be built into your application (increasing its size some) and you will not need a DLL.
If using CMake to configure your application, you can tell CMake to use the static versions of the Boost libraries using Boost_USE_STATIC_LIBS:
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost ... )
This way, the DLLs will not be required, as the requisite Boost definitions will be built into your application via the static libraries.