Answer the question
In order to leave comments, you need to log in
Why can't the linker see the function from the static library?
I work in Kubuntu. One project needed to write its own static C library and add it to the qt project. gcc compiler.
The actual error report:
g++ -Wl,-rpath,/opt/Qt/5.11.0/gcc_64/lib -o M_un main.o mainwindow.o moc_mainwindow.o -L/./lib/libmy2.a -L/opt/Qt/5.11.0/gcc_64/lib -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread
mainwindow.o: In function `MainWindow::MainWindow(QWidget*)':
/home/aleksandr/build-M_un-Desktop_Qt_5_11_0_GCC_64bit-Debug/../M_un/mainwindow.cpp:22: undefined reference to `show_sign'
collect2: error: ld returned 1 exit status
Makefile:258: recipe for target 'M_un' failed
make: *** [M_un] Error 1
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include "string.h"
extern "C"
{
#include <mylib.h>
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
QString s;
ui->setupUi(this);
unsigned int sign;
float x;
bool ok;
x = 34.7;
sign = show_sign(x);
s = QString::number(sign);
ui->sign->setText(s);
}
MainWindow::~MainWindow()
{
delete ui;
}
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = M_un
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
INCLUDEPATH += ./lib
LIBS += -L/./lib/libmy2.a
#include <stdlib.h>
unsigned int show_sign(float x)
{
float f = x;
unsigned int* p = (unsigned int*) &f;
unsigned int k = 2147483648;
unsigned int u = (p[0] & k)/k;
return u;
}
extern unsigned int show_sign(float x);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question