Comments (3)
I also see this error, and I understand the cause.
In the latest versions of gcc, this error is caused because variables are being defined in multiple places as the errors state. This is because variables are being initialized in the .h files, and these .h files are being included in multiple routines. The "modern" solution, is to define the various variables in the .h files as extern, but not to intialize them there. Instead one intializes them in a single .c routine.
the -fcommon switch sorts this out. See the explanation here, which notes among other things that this, but with a possible performance penalty.
from hotpants.
In linux adding -fcommon to CFLAGS in makefile doesn't help:
CFLAGS=-m32 -msse2 -mfpmath=sse -Wall -fno-omit-frame-pointer -fmax-errors=15 -fcommon
This still throws 'multiple definition' issue and compiler doesn't produce 'cod4x18_dedrun' file.
How to solve this?
from hotpants.
To modify your Makefile to add the -fcommon flag and potentially address multiple definition issues when compiling your project with GCC version 10 or later, follow these steps:
Open the Makefile: Use a text editor of your choice to open the Makefile. You mentioned earlier that you use nano, so you can open it with:
bash
复制代码
nano Makefile
Locate the COPTS Variable: This variable holds the compilation options for your project. It is already set up with several flags.
Add -fcommon to COPTS: Append the -fcommon flag to the existing flags in the COPTS variable. It should look like this:
makefile
复制代码
COPTS = -funroll-loops -O3 -ansi -std=c99 -pedantic-errors -Wall -I$(CFITSIOINCDIR) -D_GNU_SOURCE -fcommon
Adding -fcommon will instruct the compiler to place uninitialized global variables in a common block, which can be shared between different compiled source files. This approach can solve the multiple definition linker errors but may result in slightly less efficient code. This change is recommended if the codebase relies on older C standards or practices where multiple definitions are expected.
Save and Close: After adding the flag, save the file and exit the text editor. If you’re using nano, you can do this by pressing Ctrl+X to close, then Y to save the changes, followed by Enter to confirm.
Recompile Your Project: Go back to your terminal and run the make command to rebuild your project with the new compiler settings:
bash
复制代码
make clean
make
The make clean command is used to clean out all objects and binaries from the previous build, ensuring that the next build is completely fresh.
Check for Errors: Verify if the compilation completes without the multiple definition errors. If the errors persist, there may be other issues in the code or build system settings that need attention.
This process should help in resolving build issues related to the stricter linking behavior of newer GCC versions. If the problem continues, reviewing the source code for incorrect global variable usage or further adjusting the build settings might be necessary.
from hotpants.
Related Issues (5)
- Build issues on CentOS 5-7 HOT 1
- installation problem HOT 3
- Installation issue HOT 3
- installation problem on Ubuntu HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hotpants.