ldd outputs statically linked on a shared library

╄→尐↘猪︶ㄣ 提交于 2021-01-27 17:04:10

问题


I am trying to create a shared library libddv3djava.so

I compile sources for libddv3djava.so like so:

~/Programming/intellijprojects/ddv3dbindingstest/src $ g++ -c -Wall -Werror -I. -I /usr/lib/jvm/java-8-oracle/include/ -I /usr/lib/jvm/java-8-oracle/include/linux/ -fpic com_ddv3d_Ddv3dBinding.cpp

Creating libddv3djava.so:

~/Programming/intellijprojects/ddv3dbindingstest/src $ g++ -shared -o libddv3djava.so com_ddv3d_Ddv3dBinding.o

When I do ldd on libddv3djava.so:

~/Programming/intellijprojects/ddv3dbindingstest/src $ ldd libddv3djava.so         statically linked

Problem:

It say's libddv3djava.so is statically linked. I created libddv3djava.so with -shared so this makes me confused.

Question:

Why does ldd output statically linked, when libddv3djava.so isn't statically linked?

Additional info:

I'm not sure if the following is of any relevance, but it could be; libddv3djava.so is dependent on another shared library I created called libddv3d.so. Basically libddv3djava.so is a JNI-wrapper around libddv3d.so. Posting sources:

com_ddv3d_Ddv3dBinding.h:

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_ddv3d_Ddv3dBinding */

#ifndef _Included_com_ddv3d_Ddv3dBinding
#define _Included_com_ddv3d_Ddv3dBinding
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     com_ddv3d_Ddv3dBinding
 * Method:    initialize
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_com_ddv3d_Ddv3dBinding_initialize
  (JNIEnv *, jobject);

/*
 * Class:     com_ddv3d_Ddv3dBinding
 * Method:    sendDrawableData
 * Signature: (FFFFFFFI)V
 */
JNIEXPORT void JNICALL Java_com_ddv3d_Ddv3dBinding_sendDrawableData
  (JNIEnv *, jobject, jfloat, jfloat, jfloat, jfloat, jfloat, jfloat, jfloat, jint);

/*
 * Class:     com_ddv3d_Ddv3dBinding
 * Method:    finished
 * Signature: ()Z
 */
JNIEXPORT jboolean JNICALL Java_com_ddv3d_Ddv3dBinding_finished
  (JNIEnv *, jobject);

/*
 * Class:     com_ddv3d_Ddv3dBinding
 * Method:    cleanup
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_com_ddv3d_Ddv3dBinding_cleanup
  (JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif

com_ddv3d_Ddv3dBinding.cpp:

#include <jni.h>
#include <ddv3d.h>
#include "com_ddv3d_Ddv3dBinding.h"

JNIEXPORT void JNICALL Java_com_ddv3d_Ddv3dBinding_initialize(JNIEnv *env, jobject thisObj)
{
    ddv3d::initialize();
    return;
}
JNIEXPORT void JNICALL Java_com_ddv3d_Ddv3dBinding_sendDrawableData(JNIEnv *env, jobject thisObj,
                jfloat positionX, jfloat positionY, jfloat positionZ,
                jfloat angle,
                jfloat rotationAxisX, jfloat rotationAxisY, jfloat rotationAxisZ,
                jint type)
{
    ddv3d::sendDrawableData(positionX, positionY, positionZ,
                angle,
                rotationAxisX, rotationAxisY, rotationAxisZ,
                type);
    return;
}
JNIEXPORT jboolean JNICALL Java_com_ddv3d_Ddv3dBinding_finished(JNIEnv *env, jobject thisObj)
{
    return ddv3d::finished();
}
JNIEXPORT void JNICALL Java_com_ddv3d_Ddv3dBinding_cleanup(JNIEnv *env, jobject thisObj)
{
    ddv3d::cleanup();
    return;
}

回答1:


ldd shows which shared libraries a library or executable needs. In this case none, because libddv3djava.so is statically linked.

The compiler flag -fpic and linker flag -shared enables libddv3djava.so to be used as a shared object which is something else.

To make libddv3djava.so depend on the shared library file libddv3d.so it must be added on to the linker command.

g++ -shared -o libddv3djava.so -lddvd3d com_ddv3d_Ddv3dBinding.o

If libddv3d.so isn't found you can add extra path's to search using -L flag.



来源:https://stackoverflow.com/questions/24491381/ldd-outputs-statically-linked-on-a-shared-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!