pybind / pybind/pybind11

[BUG]: C function named "uncompress" will not be executed

Open
#4,481 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

triage
Dominant language
C++
Stars
18k
Forks
2.3k
Avg merge
5d 17h
Merged PRs (30d)
10

Description

Required prerequisites
What version (or hash if on master) of pybind11 are you using?

master

Problem description

There are three files. all.h defined a C function named "uncompress", and the function is implemented in all.c

  • all.h
- extern "C" {
#endif
extern int uncompress(const char* f,char* f1);
#ifdef __cplusplus
}
  • all.c
#include "all.h"
extern int uncompress(const char *file, char *uncfile){
	return 1;
}

and a pybind11 interface test.cpp

  • test.cpp
#include <pybind11/pybind11.h>
#include "all.h"

namespace py = pybind11;

PYBIND11_MODULE(libtest, m) {
    m.doc() = "test"; // optional module docstring
    m.def("uncompress",&uncompress,"test");
}

After compiling it to a library libtest.so, and call it in test.py by

import libtest
libtest.uncompress("a","b")

It will return -3 and gdb even can't entry this function. I debugged this problem, and found that it called a function uncompress@plt at address 0x7fe0ac66f3a8, but our function uncompress is at 0x7fe0ac735e15. That's very weird. The detail of them are

-exec info symbol 0x7fe0ac66f3a8
uncompress@plt in section .plt.got of libtest.so
-exec info symbol 0x7fe0ac735e15
uncompress in section .text of librtkbind.so

Seems there is a duplicate name function. I know I can change the name in my code, but I use the rtklib, they won't change. So how can I do?

Reproducible example code
There is a simple demo in https://github.com/ebhrz/pybind_issue.git, but the pybind11 header directory should be changed in the CMakeLists.txt.
Is this a regression? Put the last known working version here if it is.

Not a regression

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the linked demo and reviewing CMakeLists.txt, all.h, all.c, test.cpp, and test.py. Inspect why the call resolves to uncompress@plt instead of the implementation shown in all.c. Done means the reported behavior is explained and a supported fix or clear guidance lets the intended function be called without renaming it.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp, python
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.