I'm trying to deploy a Solana program created with Anchor framework. The program compiles successfully with both cargo build
and anchor build
commands, but when I try to deploy it using anchor deploy
, I'm receiving the following error:
Deploying cluster: https://api.devnet.solana.com
Upgrade authority: /home/joao-pedro/.config/solana/id.json
Deploying program "sollearning"...
Program path: /home/joao-pedro/Documents/projects/new-sollearning/sollearning/target/deploy/sollearning.so...
Error: ELF error: ELF error: Multiple or no text sections, consider removing llc option: -function-sections
There was a problem deploying: Output { status: ExitStatus(unix_wait_status(256)), stdout: "", stderr: "" }.
This happens regardless of whether I try to deploy to localnet (using a local solana-test-validator
) or to devnet - the same error occurs in both environments. The text section isn't generated, and I don't know why.
The strange part is that the build process seems to complete without errors:
anchor build
runs successfully and produces a.so
file in the target directorycargo build
completes without errorscargo check
passes
But when trying to deploy, the ELF file seems to be incorrectly generated, even though there are no build errors.
I've also tried:
- Cleaning the project with
anchor clean
and rebuilding - Checking for compatibility issues between Solana CLI and Anchor versions
- Verifying the Cargo.toml configuration for any problematic compiler flags
- Uninstalling and reinstalling the tools (Solana, Rust, Anchor, etc.)
- Migrating the project and all its files to a completely fresh directory, but the issue persisted
- Investigating the generated .so file, which is suspiciously small (only 784 bytes) despite the build process completing without any errors or warnings
Project Structure
This is a standard Anchor project created with anchor init
. The program appears to build correctly, but the generated .so
file seems to have issues with its ELF format.
Environment
- Solana CLI version: solana-cli 2.1.16 (src:a5744e79; feat:3271415109, client:Agave)
- Anchor version: anchor-cli 0.31.0
- Rust version: rustc 1.87.0-nightly (4d30011f6 2025-03-15)
- Operating System: Ubuntu 24.04.2 LTS (Noble)
Why is this happening and how can I try to resolve it?