static link to libmemkind

84 views
Skip to first unread message

chris....@gmail.com

unread,
Apr 15, 2019, 11:31:09 PM4/15/19
to pmem
Hi experts,
I am working on a project in which I want to statically link the libmemkind. I copied the libmemkind.a in the libmemkind/.libs/ and header file to my project and try to link it. But it reports

./lib/libmemkind.a: member ./lib/libmemkind.a(libjemalloc_pic.a) in archive is not an object


collect2: error: ld returned 1 exit status


I wrote the makefile of my project my self. I understand I might need to modify the Makefile.am in libmemkind, but I am not quite familiar with automake and libtool stuff. 
Is there someone could help to tell me how I can make it quickly and correctly?

Thanks,
Chris 

Adrian Jackson

unread,
Apr 16, 2019, 12:55:37 PM4/16/19
to chris....@gmail.com, pmem
Hi,

It really depends on how you are actually linking in your Makefile. Have you added the library directory to a -L flag and added the library as -lmemkind?

cheers

adrianj

--
You received this message because you are subscribed to the Google Groups "pmem" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pmem+uns...@googlegroups.com.
To post to this group, send email to pm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pmem/f429f9c3-2cfb-4062-8c88-ee2fa73baa66%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

chris....@gmail.com

unread,
Apr 16, 2019, 11:03:22 PM4/16/19
to pmem
Hi Adrianj,
Thanks a lot for your reply. I did add the -L and -I flag both. It's written like 

g++ -std=c++11 -I./deps/memkind/include/ -L./deps/memkind/.libs/ -Wl,--whole-archive -Bstatic -lmemkind -Wl,--no-whole-archive -Bdynamic-lpthread ....


But no matter how I try, it would always report libmemkind.a(libjemalloc_pic.a) in archive is not an object.

I took a brief look at the Makefile.am in the memkind folder, the static lib is created in the following code:

static_lib: jemalloc/obj/lib/libjemalloc_pic.a libmemkind.la


        bash -c "ar -M < <(echo -e '$(ar_prog)')"


        cp libmemkind.a .libs/


        rm libmemkind.a



But libmemkind.la is defined as 

lib_LTLIBRARIES = libmemkind.la


which means it's a dynamic lib source file.

So I guess making the static lib from libmemkind.la here should not work. But correct me if I mistaken it. 

Thanks,
Chris



在 2019年4月17日星期三 UTC+8上午12:55:37,adrianj.jackson写道:
Hi,

It really depends on how you are actually linking in your Makefile. Have you added the library directory to a -L flag and added the library as -lmemkind?

cheers

adrianj

On Tue, Apr 16, 2019 at 4:31 AM <chris...@gmail.com> wrote:
Hi experts,
I am working on a project in which I want to statically link the libmemkind. I copied the libmemkind.a in the libmemkind/.libs/ and header file to my project and try to link it. But it reports

./lib/libmemkind.a: member ./lib/libmemkind.a(libjemalloc_pic.a) in archive is not an object


collect2: error: ld returned 1 exit status


I wrote the makefile of my project my self. I understand I might need to modify the Makefile.am in libmemkind, but I am not quite familiar with automake and libtool stuff. 
Is there someone could help to tell me how I can make it quickly and correctly?

Thanks,
Chris 

--
You received this message because you are subscribed to the Google Groups "pmem" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pm...@googlegroups.com.

Michal Biesek

unread,
Apr 17, 2019, 5:01:44 AM4/17/19
to pmem
Hi,

There is an information on static linking in http://memkind.github.io/memkind/man_pages/memkind.html

For working example with static linking, please see following gist:


Best Regards

chris....@gmail.com

unread,
Apr 17, 2019, 9:52:09 AM4/17/19
to pmem
Hi Micheal,
Thanks for the reply. Your example works. And mine was not actually the problem of makefile at all but due to the lack of -lnuma and -ldl. Now I can statically link the libmemkind though I need to link two more dynamic libs. Those are basic libs, I'll see if my problem can be resolved. Thanks a lot for your example.

Here is another problem about the memkind. In which it has a function memkind_base_addr.
But in the latest version I found this function is gone. Checking a little deeper, I found the way of the extent alloc of the arena is different. In memkind_pmem_mmap, the old version has code like this 
    if ((errno = posix_fallocate(priv->fd, priv->offset, size)) != 0) {
        pthread_mutex_unlock(&priv->pmem_lock);
        return MAP_FAILED;
    }
result = priv->addr + priv->offset;
priv->offset += size;..







在 2019年4月17日星期三 UTC+8下午5:01:44,Michal Biesek写道:

chris....@gmail.com

unread,
Apr 17, 2019, 10:04:10 AM4/17/19
to pmem
Last one was sent by mistake.
Hi Micheal,
Thanks for the reply. Your example works. And mine was not actually the problem of makefile at all but due to the lack of -lnuma and -ldl. Now I can statically link the libmemkind though I need to link two more dynamic libs. Those are basic libs, I'll see if my problem can be resolved. Thanks a lot for your example.

Here is another problem about the memkind. In which it has a function memkind_base_addr.
But in the latest version I found this function is gone. Checking a little deeper, I found the way of the extent alloc of the arena is different. In memkind_pmem_mmap, the old version has code like this 
    if ((errno = posix_fallocate(priv->fd, priv->offset, size)) != 0) {
        pthread_mutex_unlock(&priv->pmem_lock);
        return MAP_FAILED;
    }
    result = priv->addr + priv->offset;
    priv->offset += size;

In the new version, it would mmap a new area and give a totally a brand new address to the extent. 
I understand that the new version is much more robust. But I need a function to judge if a certain pointer belongs to a memkind. 
While I still can use the old version code, I want to know if there is a way I can configure the latest libmemkind and try to get a base address from some api?


Thanks,
Chris



在 2019年4月17日星期三 UTC+8下午9:52:09,chris...@gmail.com写道:

Marcin Ślusarz

unread,
Apr 17, 2019, 5:19:06 PM4/17/19
to Michal Biesek, pmem
FTR, if -lnuma and -ldl are both needed then memkind.pc should have this line:

Libs.private: -lnuma -ldl

With this line memkind detection using pkg-config should pick up these flags automatically when linking statically.

To unsubscribe from this group and stop receiving emails from it, send an email to pmem+uns...@googlegroups.com.

To post to this group, send email to pm...@googlegroups.com.

Michal Biesek

unread,
Apr 18, 2019, 5:06:01 AM4/18/19
to pmem
Hi,

Regarding your question to judge if certain pointer belongs to a memkind - you could use function introduced in latest release: memkind_detect_kind() to recognize a kind from a memory allocation.

See example usage of this function here:

I am not aware of your use case for getting the base address of memkind but just to letting you know please read about detecting mechanism of previously allocated memory

Best Regards Michal

chris....@gmail.com

unread,
Apr 18, 2019, 7:56:04 AM4/18/19
to pmem
Hi Michal and Marcin,
Many thanks for your information and your example too. 

Thanks,
Chris Yu

在 2019年4月18日星期四 UTC+8下午5:06:01,Michal Biesek写道:
Reply all
Reply to author
Forward
0 new messages