未定义的功能外部标题错误Android NDK

发布于 2025-02-09 09:59:12 字数 3238 浏览 1 评论 0原文

我目前正在将静态库链接到我的Android项目,其中包含我要使用的函数时,发生的问题是我从Android Project中调用静态库的函数时,功能定义在.cpp文件中,我构建失败。例如,如果该功能通过类在标题中定义,则该项目会编译并运行。

.CPP文件与定义一起编译,并且该项目仍然输出没有定义的错误。

编辑:我注意到功能输出的新错误消息,即它不是精灵对象。

静态库中的Android项目调用功能:

Example.h
void example();

Example.cpp
void example()
{
} //Error

示例。H

class example
{
public:
  void example()
  {

  }//Compiles
}

错误:

“ c:\ user \ user \ user \ appData \ local \ android \ sdk \ ndk \ \ ndk \ 21.4.4.7075529 \ toolchains \ llvm \ prebuilt \ prebuilt \ windows-x86_64 \ bin /../ 4.9.x /../../../../../ i686-linux-android/bin \ ld“ -z noexecstack--warn-shared-textrel -z Now -z relro-z relro -hash-style =两者都-enable-new-dtags -eh-frame-hdr -m elf_i386 -shared -o“ debug \\ android-x86 \\ x86 \\ x86 \\ libproject.so” c:\ user \ user \ user \ user \ user \ user \ user \ appdata \ appdata sdk \ ndk \ \ 21.4.7075529 \ toolchains \ llvm \ prebuilt \ windows-x86_64 \ bin /../ sysroot/usr/usr/usr/lib/i686-linux-android/16 ProjectFolder\\Debug\\Android-x86\\x86" "-LC:\\ProjectFolder\\ProjectFolder\\StaticLibrary" "-LC:\\ProjectFolder\\ProjectFolder\\StaticLibrary\\Source" -u ANativeActivity_onCreate "-LC :\ user \ user \ user \ appdata \ local \ android \ sdk \ ndk \ 21.4.7075529 \ toolchains \ llvm \ prebuilt \ prebuilt \ windows-x86_64 \ lib lib lib lib \ clang \ clang \ clang \ clang \ 9.0.0.0.0.0.9 \ lib \ lib \ linc \ linc: \ user \ appdata \ local \ android \ sdk \ ndk \ \ 21.4.4.7075529 \ toolchains \ llvm \ prebuilt \ prebuilt \ windows-x86_64 \ bin /../ \ user \ user \ user \ appdata \ local \ android \ sdk \ ndk \ \ \ \ \ 21.4.7075529 \ toolchains \ llvm \ prebuilt \ prebuilt \ windows-x86_64 \ bin /../ lc:\ user \ user \ user \ appdata \ local \ android \ sdk \ ndk \ 21.4.4.7075529 \ toolchains \ llvm \ prebuilt \ prebuilt \ windows-x86_64 \ bin /../ lc:\ user \ user \ appdata \ local \ android \ sdk \ ndk \ ndk \ 21.4.7075529 \ toolchains \ llvm \ prebuilt \ prebuilt \ windows-x86_64 \ bin /../ ..../../../../../../i686-linux-android/lib“” -lc:\ users \ user \ user \ appdata \ local \ android \ android \ sdk \ ndk \ ndk \ 21.4.7075529 \ toolchains \ llvm \ llvm \ llvm \ prebuilt \ prebuilt \ prebuilt \ windows -x86_64\bin/../sysroot/usr/lib" --exclude-libs libgcc.a --exclude-libs libatomic.a -z noexecstack -z relro --build-id=md5 --no-undefined -z现在“ debug \\ android -x86 \\ main.o” -legl -lglesv2 -landroid -latomic -lstaticlibrary“ c:\\ user \\ user \\ user \\ user \\ appdata \\ appdata \\ local \\ android android android android \\ sdk \\ sdk \\ sdk \\ ndk \ \ \ \ \ \ \ \ \ \ \ \ \ \ \\ 21.4.7075529 \\工具链\\ llvm \\ prebuilt \\ windows-x86_64 \\ sysroot \\ usr \\ usr \\ lib \\ i686-linux-android \\ \\ \\ \\ \\ \\ \\ \\ libc ++ libc ++ _共享-lm -lgcc -ldl -lc -lgcc -ldl“ c:\ users \ user \ user \ appdata \ local \ android \ android \ sdk \ ndk \ ndk \ 21.4.4.7075529 \ toolchains \ toolchains \ llvm \ llvm \ llvm /USR/lib/i686-linux-android/16 \crtend_so.o” 1> c:\ projectFolder \ projectFolder \ projectFolder/main.cpp(10):错误:对'functionName()''' 1> c:\ projectFolder \ projectFolder \ projectFolder/main.cpp(10):错误:clang ++:错误:linker命令失败,出口代码1

I am currently linking a static library to my Android Project which contains the functions I want to use, the problem that occurs is when I call a function from the static library in Android Project, and the function definition is in a .cpp file, my build fails. If that function is defined in a header through a class for example, the project compiles and runs.

The .cpp file is compiled with the definition and the project still outputs an error of no definition.

Edit: I noticed a new error message of the function outputting that it's not an ELF object.

Android Project Calls Function from Static Library:

Example.h
void example();

Example.cpp
void example()
{
} //Error

Example.h

class example
{
public:
  void example()
  {

  }//Compiles
}

Error:

"C:\Users\User\AppData\Local\Android\Sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\bin/../lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin\ld" -z noexecstack --warn-shared-textrel -z now -z relro --hash-style=both --enable-new-dtags --eh-frame-hdr -m elf_i386 -shared -o "Debug\\Android-x86\\x86\\libProject.so" "C:\Users\User\AppData\Local\Android\Sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\bin/../sysroot/usr/lib/i686-linux-android/16\crtbegin_so.o" "-LC:\\ProjectFolder\\ProjectFolder\\Debug\\Android-x86\\x86" "-LC:\\ProjectFolder\\ProjectFolder\\StaticLibrary" "-LC:\\ProjectFolder\\ProjectFolder\\StaticLibrary\\Source" -u ANativeActivity_onCreate "-LC:\Users\User\AppData\Local\Android\Sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\lib64\clang\9.0.9\lib\linux\i386" "-LC:\Users\User\AppData\Local\Android\Sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\bin/../lib/gcc/i686-linux-android/4.9.x" "-LC:\Users\User\AppData\Local\Android\Sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\bin/../sysroot/usr/lib/i686-linux-android/16" "-LC:\Users\User\AppData\Local\Android\Sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\bin/../sysroot/usr/lib/i686-linux-android" "-LC:\Users\User\AppData\Local\Android\Sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\bin/../lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/lib" "-LC:\Users\User\AppData\Local\Android\Sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\bin/../sysroot/usr/lib" --exclude-libs libgcc.a --exclude-libs libatomic.a -z noexecstack -z relro --build-id=md5 --no-undefined -z now "Debug\\Android-x86\\Main.o" -lEGL -lGLESv2 -landroid -latomic -lStaticLibrary "C:\\Users\\User\\AppData\\Local\\Android\\Sdk\\ndk\\21.4.7075529\\toolchains\\llvm\\prebuilt\\windows-x86_64\\sysroot\\usr\\lib\\i686-linux-android\\libc++_shared.so" -soname=libProject.so -lc++ -lm -lgcc -ldl -lc -lgcc -ldl "C:\Users\User\AppData\Local\Android\Sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\bin/../sysroot/usr/lib/i686-linux-android/16\crtend_so.o"
1>C:\ProjectFolder\ProjectFolder\ProjectFolder/Main.cpp(10): error : undefined reference to 'FunctionName()'
1>C:\ProjectFolder\ProjectFolder\ProjectFolder/Main.cpp(10): error : clang++: error: linker command failed with exit code 1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

醉梦枕江山 2025-02-16 09:59:12

链接器清楚地说对'functionName()''的未定义引用,

换句话说,它找不到带有functionname()实现的源文件。确保将文件编译或将实现放置在具有相同名称的同一名称空间中(在这种情况下没有任何名称空间)。

The linker clearly says undefined reference to 'FunctionName()'

In other words it can't find the source file with FunctionName() implementation. Make sure the file is compiled or implementation is placed in the same namespace with the same name (in this particular case without any namespace).

鱼窥荷 2025-02-16 09:59:12

我尝试将所有静态库文件移至一个新项目,似乎以前的静态图书馆Visual Studio项目已损坏,然后转到了一个新的清洁项目。

I tried moving all my static library files to a new project and it seems that the previous static library Visual Studio project was corrupted, after moving over to a new clean project everything compiled.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文