|
Re: Linker can't "recognize" function, defined in another source file [message #1760041 is a reply to message #1760026] |
Fri, 21 April 2017 12:19 |
Pavel Yermolenko Messages: 26 Registered: June 2015 |
Junior Member |
|
|
Once the timer_wr_prd function is moved in the main source file, the project is built without errors. Strange ...
void timer_wr_prd(alt_u32 timer_base, alt_u32 prd) {
alt_u16 high, low;
/* unpack 32-bit timeout period into two 16-bit half words */
high = (alt_u16) (prd >> 16);
low = (alt_u16) (prd & 0x0000ffff);
/* write timeout period */
IOWR(timer_base, TIMER_PRDH_REG_OFT, high);
IOWR(timer_base, TIMER_PRDL_REG_OFT, low);
/* configure timer to start, continuous mode; enable interrupt */
IOWR(timer_base, TIMER_CTRL_REG_OFT, 0x0007);
}
void sys_init() {
btn_clear(BTN_BASE);
timer_wr_prd(USR_TIMER_BASE, 150000);
}
int main() {
LED led(0);
sys_init();
while(1)
{
set_speed(led);
led.flash();
led.move();
};
}
|
|
|
|
|
|
Re: Linker can't "recognize" function, defined in another source file [message #1760093 is a reply to message #1760066] |
Sat, 22 April 2017 09:50 |
Pavel Yermolenko Messages: 26 Registered: June 2015 |
Junior Member |
|
|
Thanks Tauno,
Indeed, I forgot these linkage issues.
Nevertheless alternating linkage inside .h file (where function is declared) didn't work.
E.g., modifying
void timer_wr_prd(alt_u32 timer_base, alt_u32 prd);
to
extern "C" void timer_wr_prd(alt_u32 timer_base, alt_u32 prd);
generates error:
chu_timer_drv.h:30:8: error: expected identifier or '(' before string constant
extern "C" void timer_wr_prd(alt_u32 timer_base, alt_u32 prd);
^
make: *** [obj/default/chu_timer_drv.o] Error 1
But when I do it in the main source file, wrapping header, it works.
E.g.
#include "chu_timer_drv.h"
becomes
extern "C" {
#include "chu_timer_drv.h"
}
This last construction resolves the issue, i.e. "C" function is recognized while linking with "CPP" source.
[Updated on: Sat, 22 April 2017 09:51] Report message to a moderator
|
|
|
Re: Linker can't "recognize" function, defined in another source file [message #1760100 is a reply to message #1760093] |
Sat, 22 April 2017 14:50 |
David Vavra Messages: 1426 Registered: October 2012 |
Senior Member |
|
|
extern "C" is valid only in C++.
The error you are getting is when compiling chu_timer_drv.c
Either use extern "C" in when you need it in a C++ module or surround it in the header as follows
#ifdef __cplusplus
extern "C" {
#endif
:
// c linkage code here
:
#ifdef __cplusplus
}
#endif
NOTE: not all compilers define __cplusplus so you may need to define it yourself on the compile command line when using C++.
ANSI/ISO compilers should have it though.
[Updated on: Sun, 23 April 2017 03:11] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03669 seconds