You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 16.04下编译Armadillo C++库报错求助

Hey there! Let's work through this Armadillo compilation error together. Since your command cuts off at -lbl..., I'll assume you meant -lblas — let's dive into common fixes for this scenario:

Troubleshooting Armadillo Compilation Errors

1. Fix Your Compilation Command

First, make sure you're using the complete, correctly ordered linker flags. Linkers process libraries in the order they're listed, so Armadillo should come after LAPACK/BLAS (or test both orders if one fails). Try this full command:

g++ example1.cpp -o example1 -O2 -llapack -lblas -larmadillo

Or the more standard order (sometimes works depending on your system):

g++ example1.cpp -o example1 -O2 -larmadillo -llapack -lblas

2. Verify Armadillo Detected LAPACK/BLAS During Installation

Armadillo needs to find LAPACK and BLAS when you build it. To check:

  • Go back to the directory where you ran cmake . for Armadillo.
  • Open the CMakeCache.txt file and look for these lines:
    ARMA_USE_LAPACK:BOOL=ON
    ARMA_USE_BLAS:BOOL=ON
    

If either is set to OFF, Armadillo didn't detect the libraries. Reinstall LAPACK/BLAS first, then re-run Armadillo's setup:

sudo apt-get install --reinstall liblapack-dev libblas-dev
cd /path/to/armadillo-source
rm CMakeCache.txt
cmake .
make
sudo make install

3. Confirm Library Paths Exist

Sometimes the linker can't find installed libraries. Run these checks:

# Check if LAPACK is in standard paths
ls /usr/lib/liblapack.so
# Check if BLAS is in standard paths
ls /usr/lib/libblas.so

If these return "No such file or directory", the libraries might be in /usr/local/lib — add that path to your compilation command with the -L flag:

g++ example1.cpp -o example1 -O2 -L/usr/local/lib -larmadillo -llapack -lblas

4. Test a Minimal Program to Rule Out Code Issues

Create a tiny test file test_arma.cpp to confirm the library itself works:

#include <armadillo>
using namespace arma;

int main() {
  mat A = randu<mat>(4,4);
  mat B = inv(A);
  mat C = A * B;
  C.print("A*inv(A) =");
  return 0;
}

Compile it with the corrected command. If this runs without errors, the problem is in your original example1.cpp code, not the library setup.

5. Use CMake (Easier Alternative for Beginners)

Since you already have CMake installed, let it handle linker flags automatically. Create a CMakeLists.txt in your project folder:

cmake_minimum_required(VERSION 3.10)
project(arma_example)

find_package(Armadillo REQUIRED)
include_directories(${ARMADILLO_INCLUDE_DIRS})

add_executable(example1 example1.cpp)
target_link_libraries(example1 ${ARMADILLO_LIBRARIES})

Then build with these commands:

mkdir build && cd build
cmake ..
make

This avoids manual flag hunting and ensures all dependencies are correctly linked.


内容的提问来源于stack exchange,提问作者Sai Chaithanya Adapa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 12:25:46