Unique shared library issues
Problem description
Recently, when I tried to link a self-built C language shared library to a local project, I encountered a link error and prompted "Undefined reference". The error message is as follows:
<code>/bin/ld: /tmp/cchb7mj8.o: in function `sdl_main': main.c:(.text 0x3c): undefined reference to `sdl_enterappmaincallbacks' ... (其他类似的未定义引用) ... collect2: error: ld returned 1 exit status make: *** [makefile:7: all] error 1</code>
Troubleshooting process
Trying to recompile the library multiple times and trying different methods, none of them worked. After searching for relevant information on search engines, I found that someone encountered similar problems in a forum, but was using a 32-bit toolchain, while my toolchain was 64-bit. After excluding toolchain version differences, consider trying different compilers.
Solution
The problem was solved after initially compiling using GCC and switching to Clang.
Problem recurrence and analysis
To understand the root cause of the problem, a simple test project was created:
- lib.h:
<code class="c">#pragma once int add(int a, int b);</code>
- lib.c:
<code class="c">#include "lib.h" int add(int a, int b) { return ab; }</code>
- main.c:
<code class="c">#include "lib.h" #include <stdio.h> int main () { printf("4 3=%d\n", add(4, 3)); return 0; }</stdio.h></code>
- build_so.sh (Clang compiles shared library):
<code class="bash">clang -std=c11 -c -o lib.o lib.c clang -shared -fpic -o libm.so lib.o</code>
- build_main.sh (GCC compiles the main program, links to the shared library):
<code class="bash">gcc -std=c11 -L. -l:libm.so main.c -o main</code>
Using the above script, the link failed with a similar "Undefined Reference" error:
<code>/bin/ld: /tmp/ccymm8ki.o: in function `main': main.c:(.text 0x13): undefined reference to `add' collect2: error: ld returned 1 exit status</code>
However, if the compilers in build_so.sh
and build_main.sh
are interchangeable (i.e. using GCC to compile the shared library and Clang compiles the main program), the link is successful.
in conclusion
This issue may be related to the differences in internal symbol handling between compilers when generating and linking shared libraries. When building shared libraries and executables with different compilers, you need to ensure that they are compatible. While this problem can be avoided in most cases using the same compiler, this example illustrates potential compatibility issues between different compilers. If you need to use different compilers in your project, you need to double-check and make sure that symbolic parsing is done correctly between them.
The above is the detailed content of Unique shared library issues. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The built-in quantization tools on the exchange include: 1. Binance: Provides Binance Futures quantitative module, low handling fees, and supports AI-assisted transactions. 2. OKX (Ouyi): Supports multi-account management and intelligent order routing, and provides institutional-level risk control. The independent quantitative strategy platforms include: 3. 3Commas: drag-and-drop strategy generator, suitable for multi-platform hedging arbitrage. 4. Quadency: Professional-level algorithm strategy library, supporting customized risk thresholds. 5. Pionex: Built-in 16 preset strategy, low transaction fee. Vertical domain tools include: 6. Cryptohopper: cloud-based quantitative platform, supporting 150 technical indicators. 7. Bitsgap:

How to achieve the effect of mouse scrolling event penetration? When we browse the web, we often encounter some special interaction designs. For example, on deepseek official website, �...

The download, installation and registration process of the Hong Kong Digital Currency Exchange app is very simple. Users can quickly obtain and use this app through the official app download link provided in this article. This article will introduce in detail how to download, install and register the Hong Kong Digital Currency Exchange app to ensure that every user can complete the operation smoothly.

This groundbreaking development will enable financial institutions to leverage the globally recognized ISO20022 standard to automate banking processes across different blockchain ecosystems. The Ease protocol is an enterprise-level blockchain platform designed to promote widespread adoption through easy-to-use methods. It announced today that it has successfully integrated the ISO20022 messaging standard and directly incorporated it into blockchain smart contracts. This development will enable financial institutions to easily automate banking processes in different blockchain ecosystems using the globally recognized ISO20022 standard, which is replacing the Swift messaging system. These features will be tried soon on "EaseTestnet". EaseProtocolArchitectDou

The essential Laravel extension packages for 2024 include: 1. LaravelDebugbar, used to monitor and debug code; 2. LaravelTelescope, providing detailed application monitoring; 3. LaravelHorizon, managing Redis queue tasks. These expansion packs can improve development efficiency and application performance.

The prospects of digital currency apps are broad, which are specifically reflected in: 1. Technology innovation-driven function upgrades, improving user experience through the integration of DeFi and NFT and AI and big data applications; 2. Regulatory compliance trends, global framework improvements and stricter requirements for AML and KYC; 3. Function diversification and service expansion, integrating lending, financial management and other services and optimizing user experience; 4. User base and global expansion, and the user scale is expected to exceed 1 billion in 2025.

Uniswap users can withdraw tokens from liquidity pools to their wallets to ensure asset security and liquidity. The process requires gas fees and is affected by network congestion.

The top 10 digital virtual currency trading platforms are: 1. Binance, 2. OKX, 3. Coinbase, 4. Kraken, 5. Huobi Global, 6. Bitfinex, 7. KuCoin, 8. Gemini, 9. Bitstamp, 10. Bittrex. These platforms all provide high security and a variety of trading options, suitable for different user needs.
