Reputation: 377
In Qt, I want a particular function to run when I click a button. So I made a button and used the "connect()" function to run some subroutine "initializeButtonPushed"
void MainWindow::initializeButtonPushed(){
initializePlatform();
}
simple enough. In the file "mainwindow.h" there is a line
#include "platform.h"
and inside platform.h is the definition "void initializePlatform(void);"
also in my c sources I have a platform.c file which has the actual code for this function.
In addition to this, I can already see that the .pro file for my Qt project has those files included.
So given this, it seems like the compiler should be able to find those files, but when I try compiling my code, I get error:
undefined reference to 'initializePlatform()'
collect2:error: ld returned 1 exit status
I don't know much about cpp, I usually use C but needed Qt for this program, so maybe I am missing something, but I don't see why it says my function is undefined when I can see the source file as part of my project and know the code for it is in that file.
Upvotes: 1
Views: 47
Reputation: 50190
you need this
extern "C"{
#include "platform.h"
}
this allows the c++ compiler and linker to correctly link function written in c
Upvotes: 3