does anyone have problem with linking to newmat library ?

running

#include "newmat.h"

int main()
{
    Matrix A(2,2);
}

i got linker error: undefined reference

i'm using dev c++ and have set the directories to point to the file where i stored all the header and source files ..

any thoughts?

Dani AI

Generated

An "undefined reference" at link time means the compiler saw newmat's declarations (the headers) but the linker never received the corresponding compiled definitions. In other words, putting the header files in the include path is not enough if the library's object code is not being linked. 's minimal example demonstrates the symptom; 's GCC notes are a useful pointer for how the library is built under GCC.

Typical fixes (Dev-C++ / MinGW)

  • Link the compiled library: either add the prebuilt static/shared library file (e.g. a lib*.a or .lib) to the project's linker inputs, or build newmat from its .cpp files and link the resulting archive/object files.
  • Add newmat's sources to the Dev-C++ project so they are compiled along with the application, or build a static library with ar and add it in Project → Project Options → Parameters → Linker.
  • Command-line example (adjust paths and actual library name):
g++ -I"C:\path\to\newmat\include" main.cpp -L"C:\path\to\newmat\lib" -lnewmat -o program.exe

Troubleshooting checklist

  • Linker order matters: object files and sources should appear before -l flags on the g++ command line.
  • Ensure the library format and toolchain match (MinGW vs MSVC incompatibilities will cause unresolved symbols or other link errors).
  • Verify the symbol is actually in the library with nm or objdump -t (MinGW toolchain), or pass -Wl,--verbose to the linker to see search paths and files used.
  • If a prebuilt binary is used, rebuild newmat from source with the same compiler/settings as the application.

Providing the exact unresolved symbol name and the final link command (or the library filename used) usually makes the root cause obvious.

The link below includes the configuration of newmat library in depth along with few examples.

Hope it helped, bye.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.