I recently want to learn the new feature (-Link-time optimization) of gcc with i686-4.9.0-release-posix-dwarf-rt_v3-rev1.7z; I got an error "undefined reference". Is there any mistake in my program or can anyone tell me how to use the flto ? here is may program:
the following is built into a static library
///message.h
#ifndef Message_h
#define Message_h
#ifdef __cplusplus
extern "C" {
#endif
void Message(int ok);
#ifdef __cplusplus
}
#endif
#endif
///Message.cpp
#include <stdio.h>
#include "message.h"
extern "C" {
void Message(int ok)
{
if (ok)
printf("test is ok: %d\n",ok);
else
printf("test error: %d\n",ok);
}
} // extern "C"
build option->compiler settings->other options: -flto-fuse-linker-plugin
build option->linker settings->other linker options: -flto-fuse-linker-plugin
get a static libmessage.a;
my app is as follow:
#include <iostream>
#include "message.h"
using namespace std;
int main()
{
Message(1);
cout << "Hello world!" << endl;
return 0;
}
build option->search directories->compiler: c:\myprogram\message
build option->search directories->linker: c:\myprogram\message\lib
build option->compiler settings->other options: -flto-fuse-linker-plugin
build option->linker settings->linker libraries: libmessage
build option->linker settings->other linker options: -flto-fuse-linker-plugin
when I built the app, a got an error
C:\Users\ADMINI~1\AppData\Local\Temp\ccoymopg.ltrans0.ltrans.o:ccoymopg.ltrans0.o:(.text+0x16): undefined reference to `Message'
collect2.exe: error: ld returned 1 exit status.