'How to pass compiler flags to gcc 11 so that it can accept weak variable definitions?
I've got C headers that make variable declarations without "extern", aka weak variable definitions. Compiling that code, gcc 11.2.0 MinGW gives a link error of multiple definitions. gcc 9.4.0 wsl compiles the code normally.
I guess newer version of gcc treats weak variable definitions differently. For some reasons, I cannot add "extern" in the headers. How can I compile the code by providing some compiler flags to gcc 11?
Following is a example which gcc 11 rejects:
//a.h
#ifndef A_H
#define A_H
int a;
#endif
//a.c
#include "a.h"
#include <stdio.h>
int main(){
printf("a=%d\n",a);
}
//b.c
#include "a.h"
int a=1;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
