Sort
Profile photo for Chris Reid

I imagine two things — the Docker compiler is a different version, and the default settings for the docker version is for a stripped binary. A stripped binary has the symbol table removed from the executable. This makes it leaner, but harder to debug. Docker containers are very aware of limited space and memory, so it makes sense to try to slim down programs where they can be.

30% is a lot.

Where do I start?

I’m a huge financial nerd, and have spent an embarrassing amount of time talking to people about their money habits.

Here are the biggest mistakes people are making and how to fix them:

Not having a separate high interest savings account

Having a separate account allows you to see the results of all your hard work and keep your money separate so you're less tempted to spend it.

Plus with rates above 5.00%, the interest you can earn compared to most banks really adds up.

Here is a list of the top savings accounts available today. Deposit $5 before moving on because this is one of th

Where do I start?

I’m a huge financial nerd, and have spent an embarrassing amount of time talking to people about their money habits.

Here are the biggest mistakes people are making and how to fix them:

Not having a separate high interest savings account

Having a separate account allows you to see the results of all your hard work and keep your money separate so you're less tempted to spend it.

Plus with rates above 5.00%, the interest you can earn compared to most banks really adds up.

Here is a list of the top savings accounts available today. Deposit $5 before moving on because this is one of the biggest mistakes and easiest ones to fix.

Overpaying on car insurance

You’ve heard it a million times before, but the average American family still overspends by $417/year on car insurance.

If you’ve been with the same insurer for years, chances are you are one of them.

Pull up Coverage.com, a free site that will compare prices for you, answer the questions on the page, and it will show you how much you could be saving.

That’s it. You’ll likely be saving a bunch of money. Here’s a link to give it a try.

Consistently being in debt

If you’ve got $10K+ in debt (credit cards…medical bills…anything really) you could use a debt relief program and potentially reduce by over 20%.

Here’s how to see if you qualify:

Head over to this Debt Relief comparison website here, then simply answer the questions to see if you qualify.

It’s as simple as that. You’ll likely end up paying less than you owed before and you could be debt free in as little as 2 years.

Missing out on free money to invest

It’s no secret that millionaires love investing, but for the rest of us, it can seem out of reach.

Times have changed. There are a number of investing platforms that will give you a bonus to open an account and get started. All you have to do is open the account and invest at least $25, and you could get up to $1000 in bonus.

Pretty sweet deal right? Here is a link to some of the best options.

Having bad credit

A low credit score can come back to bite you in so many ways in the future.

From that next rental application to getting approved for any type of loan or credit card, if you have a bad history with credit, the good news is you can fix it.

Head over to BankRate.com and answer a few questions to see if you qualify. It only takes a few minutes and could save you from a major upset down the line.

How to get started

Hope this helps! Here are the links to get started:

Have a separate savings account
Stop overpaying for car insurance
Finally get out of debt
Start investing with a free bonus
Fix your credit

Profile photo for Mats Petersson

There are several answers here already, making some very good points, however, I’m going to suggest a few very basic things:

  1. Run file myexecutable and compare the output from the two executable files.

    Particularly, you may have differences in what debug info is included in the files.

    Could also be that one of your builds is 32-bit, the other 64-bit, for example.
  2. Run size myexecutable.

    This will show the size of the actual executable code (called text), data and bss. If these are the same, you are good - it’s “some other stuff” in the executable file.

    If the sizes are different, then you wil

There are several answers here already, making some very good points, however, I’m going to suggest a few very basic things:

  1. Run file myexecutable and compare the output from the two executable files.

    Particularly, you may have differences in what debug info is included in the files.

    Could also be that one of your builds is 32-bit, the other 64-bit, for example.
  2. Run size myexecutable.

    This will show the size of the actual executable code (called text), data and bss. If these are the same, you are good - it’s “some other stuff” in the executable file.

    If the sizes are different, then you will, hopefully, know at least roughly where to look.

Neither of these commands will give you a direct answer to what the difference is, but it may well give you a start to look for what.

For actually solving it, yes, you will need to figure out exactly what options your compiler is using - which may include configurations in the “make” setup, environment variables, build configuration when you set up the project. And probably several other things that escapes me right now. It may also depend on precisely “what else” and “which version” is installed on the respective environments.

Profile photo for Petr Skocik

I’d look at gcc -v outputs in those two respective environments to see how the default settings of the compiler differ in them. One or more of the differing default settings should be behind the size difference.

Icon for Beginner coder

Most likely is that different static libraries are being linked in each case. Note that, if one environment is being used o test and debug a program for the other, this can be the source of highly elusive bugs. This one reason why I prefer a VM over a mess like Docker.

Profile photo for Quora User

Here’s the thing: I wish I had known these money secrets sooner. They’ve helped so many people save hundreds, secure their family’s future, and grow their bank accounts—myself included.

And honestly? Putting them to use was way easier than I expected. I bet you can knock out at least three or four of these right now—yes, even from your phone.

Don’t wait like I did. Go ahead and start using these money secrets today!

1. Cancel Your Car Insurance

You might not even realize it, but your car insurance company is probably overcharging you. In fact, they’re kind of counting on you not noticing. Luckily,

Here’s the thing: I wish I had known these money secrets sooner. They’ve helped so many people save hundreds, secure their family’s future, and grow their bank accounts—myself included.

And honestly? Putting them to use was way easier than I expected. I bet you can knock out at least three or four of these right now—yes, even from your phone.

Don’t wait like I did. Go ahead and start using these money secrets today!

1. Cancel Your Car Insurance

You might not even realize it, but your car insurance company is probably overcharging you. In fact, they’re kind of counting on you not noticing. Luckily, this problem is easy to fix.

Don’t waste your time browsing insurance sites for a better deal. A company called Insurify shows you all your options at once — people who do this save up to $996 per year.

If you tell them a bit about yourself and your vehicle, they’ll send you personalized quotes so you can compare them and find the best one for you.

Tired of overpaying for car insurance? It takes just five minutes to compare your options with Insurify and see how much you could save on car insurance.

2. Ask This Company to Get a Big Chunk of Your Debt Forgiven

A company called National Debt Relief could convince your lenders to simply get rid of a big chunk of what you owe. No bankruptcy, no loans — you don’t even need to have good credit.

If you owe at least $10,000 in unsecured debt (credit card debt, personal loans, medical bills, etc.), National Debt Relief’s experts will build you a monthly payment plan. As your payments add up, they negotiate with your creditors to reduce the amount you owe. You then pay off the rest in a lump sum.

On average, you could become debt-free within 24 to 48 months. It takes less than a minute to sign up and see how much debt you could get rid of.

3. You Can Become a Real Estate Investor for as Little as $10

Take a look at some of the world’s wealthiest people. What do they have in common? Many invest in large private real estate deals. And here’s the thing: There’s no reason you can’t, too — for as little as $10.

An investment called the Fundrise Flagship Fund lets you get started in the world of real estate by giving you access to a low-cost, diversified portfolio of private real estate. The best part? You don’t have to be the landlord. The Flagship Fund does all the heavy lifting.

With an initial investment as low as $10, your money will be invested in the Fund, which already owns more than $1 billion worth of real estate around the country, from apartment complexes to the thriving housing rental market to larger last-mile e-commerce logistics centers.

Want to invest more? Many investors choose to invest $1,000 or more. This is a Fund that can fit any type of investor’s needs. Once invested, you can track your performance from your phone and watch as properties are acquired, improved, and operated. As properties generate cash flow, you could earn money through quarterly dividend payments. And over time, you could earn money off the potential appreciation of the properties.

So if you want to get started in the world of real-estate investing, it takes just a few minutes to sign up and create an account with the Fundrise Flagship Fund.

This is a paid advertisement. Carefully consider the investment objectives, risks, charges and expenses of the Fundrise Real Estate Fund before investing. This and other information can be found in the Fund’s prospectus. Read them carefully before investing.

4. Earn Up to $50 this Month By Answering Survey Questions About the News — It’s Anonymous

The news is a heated subject these days. It’s hard not to have an opinion on it.

Good news: A website called YouGov will pay you up to $50 or more this month just to answer survey questions about politics, the economy, and other hot news topics.

Plus, it’s totally anonymous, so no one will judge you for that hot take.

When you take a quick survey (some are less than three minutes), you’ll earn points you can exchange for up to $50 in cash or gift cards to places like Walmart and Amazon. Plus, Penny Hoarder readers will get an extra 500 points for registering and another 1,000 points after completing their first survey.

It takes just a few minutes to sign up and take your first survey, and you’ll receive your points immediately.

5. Stop Paying Your Credit Card Company

If you have credit card debt, you know. The anxiety, the interest rates, the fear you’re never going to escape… but a website called AmONE wants to help.

If you owe your credit card companies $100,000 or less, AmONE will match you with a low-interest loan you can use to pay off every single one of your balances.

The benefit? You’ll be left with one bill to pay each month. And because personal loans have lower interest rates (AmONE rates start at 6.40% APR), you’ll get out of debt that much faster.

It takes less than a minute and just 10 questions to see what loans you qualify for.

6. Earn Up to $225 This Month Playing Games on Your Phone

Ever wish you could get paid just for messing around with your phone? Guess what? You totally can.

Swagbucks will pay you up to $225 a month just for installing and playing games on your phone. That’s it. Just download the app, pick the games you like, and get to playing. Don’t worry; they’ll give you plenty of games to choose from every day so you won’t get bored, and the more you play, the more you can earn.

This might sound too good to be true, but it’s already paid its users more than $429 million. You won’t get rich playing games on Swagbucks, but you could earn enough for a few grocery trips or pay a few bills every month. Not too shabby, right?

Ready to get paid while you play? Download and install the Swagbucks app today, and see how much you can earn!

Profile photo for Vishal Oza

I would first look what are your build/compiler settings between your Docker instance versus your Debian install. This might include make/cmake files. They might hint the build is set to create smaller binaries or faster binaries. If there is nothing that says the build was different, the it is possible gcc is different between Do...

Icon for Beginner coder

Which version of the compiler, with what options selected, for what target machine? You may naively think you are comparing two compilers, and if you did not compare the same version of the compiler with the same options compiling for the same architecture , you have no idea what you are comparing. It you can’t show us the command lines for each tool in each step of the toolchain, we can’t, either. The only way you can prove they are the same compiler is if you can show they are bitwise identical images. And that their libraries are bitwise identical. You have to show the command lines for eac

Which version of the compiler, with what options selected, for what target machine? You may naively think you are comparing two compilers, and if you did not compare the same version of the compiler with the same options compiling for the same architecture , you have no idea what you are comparing. It you can’t show us the command lines for each tool in each step of the toolchain, we can’t, either. The only way you can prove they are the same compiler is if you can show they are bitwise identical images. And that their libraries are bitwise identical. You have to show the command lines for each tool, and they must be absolutely identical, and you have to show the link maps. Without the link maps, you have zero evidence of difference, because file size has nothing to do with memory footprint.

Profile photo for Johnny M

I once met a man who drove a modest Toyota Corolla, wore beat-up sneakers, and looked like he’d lived the same way for decades. But what really caught my attention was when he casually mentioned he was retired at 45 with more money than he could ever spend. I couldn’t help but ask, “How did you do it?”

He smiled and said, “The secret to saving money is knowing where to look for the waste—and car insurance is one of the easiest places to start.”

He then walked me through a few strategies that I’d never thought of before. Here’s what I learned:

1. Make insurance companies fight for your business

Mos

I once met a man who drove a modest Toyota Corolla, wore beat-up sneakers, and looked like he’d lived the same way for decades. But what really caught my attention was when he casually mentioned he was retired at 45 with more money than he could ever spend. I couldn’t help but ask, “How did you do it?”

He smiled and said, “The secret to saving money is knowing where to look for the waste—and car insurance is one of the easiest places to start.”

He then walked me through a few strategies that I’d never thought of before. Here’s what I learned:

1. Make insurance companies fight for your business

Most people just stick with the same insurer year after year, but that’s what the companies are counting on. This guy used tools like Coverage.com to compare rates every time his policy came up for renewal. It only took him a few minutes, and he said he’d saved hundreds each year by letting insurers compete for his business.

Click here to try Coverage.com and see how much you could save today.

2. Take advantage of safe driver programs

He mentioned that some companies reward good drivers with significant discounts. By signing up for a program that tracked his driving habits for just a month, he qualified for a lower rate. “It’s like a test where you already know the answers,” he joked.

You can find a list of insurance companies offering safe driver discounts here and start saving on your next policy.

3. Bundle your policies

He bundled his auto insurance with his home insurance and saved big. “Most companies will give you a discount if you combine your policies with them. It’s easy money,” he explained. If you haven’t bundled yet, ask your insurer what discounts they offer—or look for new ones that do.

4. Drop coverage you don’t need

He also emphasized reassessing coverage every year. If your car isn’t worth much anymore, it might be time to drop collision or comprehensive coverage. “You shouldn’t be paying more to insure the car than it’s worth,” he said.

5. Look for hidden fees or overpriced add-ons

One of his final tips was to avoid extras like roadside assistance, which can often be purchased elsewhere for less. “It’s those little fees you don’t think about that add up,” he warned.

The Secret? Stop Overpaying

The real “secret” isn’t about cutting corners—it’s about being proactive. Car insurance companies are counting on you to stay complacent, but with tools like Coverage.com and a little effort, you can make sure you’re only paying for what you need—and saving hundreds in the process.

If you’re ready to start saving, take a moment to:

Saving money on auto insurance doesn’t have to be complicated—you just have to know where to look. If you'd like to support my work, feel free to use the links in this post—they help me continue creating valuable content.

Profile photo for Emilio Garavaglia

After reading a few answer let me give you two suggestion:

  • OP: plese change GCC to gcc (and clarify you are talking about the command, not the entire compiler suite) [Thank you for the update]
  • To the authors: please before answering consult UP TO DATE documentation, and don’t report your child’s memories. Saying “g++ is equivalent to gcc -x c++" is false (there are many important missing part!) so let me debunk what's going on
  1. GCC (all capitals) means GNU Compile Collection. It’s comprehensive of various compilers, libraries and -last but not least- a LINKER. Without it no program can be produced

After reading a few answer let me give you two suggestion:

  • OP: plese change GCC to gcc (and clarify you are talking about the command, not the entire compiler suite) [Thank you for the update]
  • To the authors: please before answering consult UP TO DATE documentation, and don’t report your child’s memories. Saying “g++ is equivalent to gcc -x c++" is false (there are many important missing part!) so let me debunk what's going on
  1. GCC (all capitals) means GNU Compile Collection. It’s comprehensive of various compilers, libraries and -last but not least- a LINKER. Without it no program can be produced.
  2. gcc (small letters) is a command-line program that -when given a set of file- try to guess the corresponding language, invoke the corresponding compilers, and -finally LINKS all the produced object by invoking a linker.

To produce a program, the linker must link not just the produced objects, but also all the libraries they may refer to. Unless of specific language standard or proprietary constructs (like module or #pragma link) the linker has NO WAY TO KNOW what are the archive containing such libraries. The only library that is always linked by default is the CRT_Startup code (or whatever is called by different compiler manufacturer) that contains only the entry and exit functions plus the minimal necessary to print error messages that is the thing that calls main after breaking up the command line words.

Now consider this program

  1. #include<cstdio> 
  2. int main() 
  3. { printf(“hello\n”); return 0; } 

save it as a main.cpp and compile it as

  1. gcc main.cpp 

It compiles and run.

Now consider this

  1. #include<cstdio> 
  2. int main() 
  3. {  
  4. auto ptr = new int; 
  5. printf(“hello\n”);  
  6. return 0;  
  7. } 

And invoke it the same.

You will get

  1. undefined reference to `operator new(unsigned long)' 

This is not a compiler error: it is a LINKER ERROR.

So what’s the fuss here?

The compiler correctly recognized the language to be C++ and did it’s job properly: it translated new int into operator new(sizeof(int)).

The problem is that while the first program use no more than a printf (most likely optimized in a puts, that is used bu the startup code itself to print his own startup failure message, and hence it is part of the C-support library) the second also use a fu**ing operator new(size_t) that’s NOT PART of the C standard library.

Consider this program

  1. #include<cstdio> 
  2.  
  3. struct boot 
  4. { 
  5. boot() { printf("Boot\n"); } 
  6. ~boot() { printf("Unboot\n"); } 
  7. }; 
  8.  
  9. boot instance = {}; 
  10.  
  11. int main() 
  12. {} 

How many of you think it does noting?

Let me give you an F.

That program (according to the ISO C++ standard) must print

  1. Boot 
  2. Unboot 

But to do that, it needs a startup code that calls boot::boot() before calling main and calls boot::~boot() after returning from it.

But if the linked startup code will not contain the part that iterate the function pointer vector resulting from the instantiation of the global static variables… your program can’t work correctly. And it should normally produce a linker error

  1. > gcc main.cpp 
  2. C:\Temp\ccgbBujR.o:main.cpp:(.xdata$_ZN4bootD1Ev+0xc): undefined reference to `__gxx_personality_seh0' 
  3. collect2.exe: error: ld returned 1 exit status 
  4.  
  5. > gcc -xc++ main.cpp 
  6. C:\Temp\ccYyt7H3.o:main.cpp:(.xdata$_ZN4bootD1Ev+0xc): undefined reference to `__gxx_personality_seh0' 
  7. collect2.exe: error: ld returned 1 exit status 
  8.  
  9. > g++ main.cpp 
  10.  
  11. > a 
  12. Boot 
  13. Unboot 

And this is the proof that saying “g++ is just gcc -xc++” is false!

As it is false also saying “I can compile C++ with gcc”: it succeeds only if no C++ specific features requiring library implementation are used. g++ ensure that the proper library modules are linked, whatever the specific invocation option may be in this or that release.

Profile photo for Quora User

Size of an executable does not mean much. Especially for Java code which requires very big JVM to run!
Similar is for Python code where py file also needs complete Python executable, python.exe.

If we look at some simple example, eg for loop:

  1. for(int a = 0; a < 100; a++) 
  2. { 
  3. } 

C/C++ compiler generated code will be three to four instructions depending on CPU.
Java generated byte code will be similar. But byte code cannot be executed and must have complete JVM launched taking lot of MBs.

If we look at C/C++ code, then two possibilities exist:

  • Statically linked libraries
  • Dynamically linked libraries

Statica

Size of an executable does not mean much. Especially for Java code which requires very big JVM to run!
Similar is for Python code where py file also needs complete Python executable, python.exe.

If we look at some simple example, eg for loop:

  1. for(int a = 0; a < 100; a++) 
  2. { 
  3. } 

C/C++ compiler generated code will be three to four instructions depending on CPU.
Java generated byte code will be similar. But byte code cannot be executed and must have complete JVM launched taking lot of MBs.

If we look at C/C++ code, then two possibilities exist:

  • Statically linked libraries
  • Dynamically linked libraries

Statically linked library means that library code (lib file) is added to the executable increasing its size. Depending how library was built, whole library might end up in the executable.
Dynamically linked means that executable uses a DLL (Windows) and only very tiny proxy layer is inside executable. Such executables are way smaller but also take longer to load. Memory wise it could be similar (depends).

Windows executables have multiple sections as well as resources, eg images. This all increases size a lot.

So, it is not possible to compare executables sizes. It is not accurate measure. But look at memory usage of a Java app and picture is different.

Develop .NET, ASP.NET, .NET Core, Xamarin or Unity applications on Windows, Mac, or Linux.
Profile photo for Chris Reid

Simple. tcc can run source code.

  1. /*demo.c */ 
  2. #include <stdio.h> 
  3. #include <stdlib.h> 
  4.  
  5. int main ( int argc, char** argv) 
  6. { 
  7. int*p = (int*)calloc(100, sizeof(int) ); 
  8.  
  9. p[0]=1; 
  10.  
  11. for(int i = 1; i < 100; i++) { p[i] = i + (p[i-1]) ;} 
  12.  
  13. for(int j = 0; j < 100; j++) { printf("%d\t" , p[j]);} 
  14. printf("\n"); 
  15.  
  16. free(p); 
  17. return 0; 
  18. } 
  19.  
  20.  
  21. tcc -run demo.c 
  22.  
  23. 1 2 4 7 11 16 22 29 37 46  
  24. 56 67 79 92 106 121 137 154 172 191 
  25. 11 232 254 277 301 326 352 379 407 436 
  26. 466 497 529 562 596 631 667 704 742 781 
  27. 821 862 904 947 991 1036 1082 1129 1177 1226 
  28. 1276 1327 1379 1432 1486 1541 1597 1654 1712 1771 
  29. 1831 1892 1954 2017 2081 2146 2212 2279 234 

Simple. tcc can run source code.

  1. /*demo.c */ 
  2. #include <stdio.h> 
  3. #include <stdlib.h> 
  4.  
  5. int main ( int argc, char** argv) 
  6. { 
  7. int*p = (int*)calloc(100, sizeof(int) ); 
  8.  
  9. p[0]=1; 
  10.  
  11. for(int i = 1; i < 100; i++) { p[i] = i + (p[i-1]) ;} 
  12.  
  13. for(int j = 0; j < 100; j++) { printf("%d\t" , p[j]);} 
  14. printf("\n"); 
  15.  
  16. free(p); 
  17. return 0; 
  18. } 
  19.  
  20.  
  21. tcc -run demo.c 
  22.  
  23. 1 2 4 7 11 16 22 29 37 46  
  24. 56 67 79 92 106 121 137 154 172 191 
  25. 11 232 254 277 301 326 352 379 407 436 
  26. 466 497 529 562 596 631 667 704 742 781 
  27. 821 862 904 947 991 1036 1082 1129 1177 1226 
  28. 1276 1327 1379 1432 1486 1541 1597 1654 1712 1771 
  29. 1831 1892 1954 2017 2081 2146 2212 2279 2347 2416 
  30. 2486 2557 2629 2702 2776 2851 2927 3004 3082 3161 
  31. 3241 3322 3404 3487 3571 3656 3742 3829 3917 4006 
  32. 4096 4187 4279 4372 4466 4561 4657 4754 4852 4951 

The author says it on his website: TCC : Tiny C Compiler

  • SMALL! You can compile and execute C code everywhere, for example on rescue disks (about 100KB for x86 TCC executable, including C preprocessor, C compiler, assembler and linker).
  • FAST! tcc generates x86 code. No byte code overhead. Compile, assemble and link several times faster than GCC.
  • UNLIMITED! Any C dynamic library can be used directly. TCC is heading torward full ISOC99 compliance. TCC can of course compile itself.
  • SAFE! tcc includes an optional memory and bound checker. Bound checked code can be mixed freely with standard code.
  • Compile and execute C source directly. No linking or assembly necessary. Full C preprocessor and GNU-like assembler included.
  • C script supported : just add '#!/usr/local/bin/tcc -run' at the first line of your C source, and execute it directly from the command line.
  • With libtcc, you can use TCC as a backend for dynamic code generation.
Profile photo for Grzegorz Antoniak

New version of GCC is compiled in older version of GCC.

Older version of GCC was compiled by using even older version of GCC.

First version of GCC could be compiled by using a different C compiler.

The first C compiler was written in a different language: BCPL, so it used BCPL compiler.

The BCPL compiler was written in BCPL itself, so new versions of BCPL needed older versions of BCPL to be compiled, similarly to GCC.

The first version of BCPL was written in AED, or Algol.

The first Algol compiler was *possibly* written in machine code by using punch cards.

Profile photo for Kartik Ayyar

Here is my mindset for comparing compilers:

Even when upgrading what seems like relatively minor version bumps of existing compilers I've seen all sorts of bugs crop up - ranging from code not compiling, to the compiler getting stuck in an infinite loop, to code that sometimes crashes, to some flags not working in the exact same way despite compatibility being advertised. These issues are a pain to debug, and sometimes the turnaround from your compiler vendor can be suboptimal ( and sometimes, even getting them a reproduce able test case to hit the problem isn't easy if you had a complicated b

Here is my mindset for comparing compilers:

Even when upgrading what seems like relatively minor version bumps of existing compilers I've seen all sorts of bugs crop up - ranging from code not compiling, to the compiler getting stuck in an infinite loop, to code that sometimes crashes, to some flags not working in the exact same way despite compatibility being advertised. These issues are a pain to debug, and sometimes the turnaround from your compiler vendor can be suboptimal ( and sometimes, even getting them a reproduce able test case to hit the problem isn't easy if you had a complicated binary which has dependences on custom tools and build scripts ). That is if you even have a compiler vendor supporting you.

At times the problems that have come up have been in code that was actually buggy but somehow worked in a previous compiler, but at the end of the day it did work and that was what was important.

While clangs's list of advantages over gcc looks interesting, the actual feature list for picking a compiler needs to prioritize reliability above everything else.

For example, the website for clang mentions that "Qt doesn't compile due to a problem in Qt." It isn't uncommon for there to be some quirks somewhere in large codebases, but if it compiles and works on gcc, this isn't Qt's problem, its clangs. 3rd party vendors will test with the defacto standard rather than an esoteric compiler

Given how fundamental a compiler is, err on the side of being absolutely conservative and paranoid when it comes to selecting compilers.

With that massive disclaimer out of the way, looking at the documentation for clang, it does seem to have some rather interesting features over gcc.

Better diagnostics:
It seems clang has far better error diagnostics than gcc, in particular it seems to be far better than gcc in terms of pinpointing where exactly parsing failed.

http://clang.llvm.org/diagnostics.html

Fast compiles:

While nice, for one file incremental builds it doesn't make too much of a difference, on the other hand for large builds while it can be quite handy, it doesn't come across as tempting enough to switch.

http://clang.llvm.org/features.html#performance

Better code analysis tool support

The article points out that the AST produced by gcc isn't as friendly towards some tools since if you have an expression in gcc which evaluates to a constant, it is replaced by a constant - this can make renaming variables hard.

If you do want to use a tool to do do this rename that is based off of clang and actually works, my advice would be to use it in a one off manner - though again, nothing worth jumping ship for.

Better IDE support

I don't see examples or specifics, so I can't comment. Personally, I consider gdb is significantly more powerful than any graphical debugger I've used by a long shot, so again, nothing interesting.

http://clang.llvm.org/features.html#ideintegration

Miscellany:

Pretty much everything else on its long list of features is an implementation detail - it doesn't affect the bottom line for developer productivity. In theory it might have cleaner internals, in practice gcc has been battle tested.

Assuming you have sane, clean makefiles such that you can make a compiler switch across your entire codebase in one place, it won't hurt to toy with it or use it for compiling your initial builds and experiment while incrementally developing, especially if its primary features are faster build times and more helpful errors.

However, out of sheer paranoia, I'd say don't use it for any shipping code.

Wait for your 3rd party libraries start coming with documentation that says they have been tested against clang . Wait for other organizations to make announcements saying they have been using clang for a while and it is working fine for them to the point you can't ignore clang.

Let someone else incur the learning cost for this activity given the risks.

Profile photo for Valdis Klētnieks

Why does GCC generate 15-20% faster code if I optimize for size instead of speed?

First off, I’d be surprised if *all* code is 15–20% faster, though there’s some reasons why *some* code might be….

Most likely, your CPU has a smallish instruction or merged L1/L2 cache, and the code didn’t fit in the cache when optimized for speed. This results in cache line misses, which slow things down.

Compiling for size makes the code fit better in cache, reducing cache misses.

Of course, this effect will depend on your exact code.

You probably want to take a really close look at the -march and -mcpu flags.

Profile photo for Lorenzo Snow

TCC is “tiny”, it’s really tiny compiler which is not a toy, it fully support many corner cases in C, it produces a small executables, if you’re learning decompilation for example, it’s easy to use TCC when you need a small build-system-environment, for education purposes, also TCC uses in other languages and compilers (Nim for example) which translates their source code into C, also some OS uses TCC as a main compiler (DeforaOS, a nice little project, if I not wrong), TCC is a good example if you want to learn bitwise operations in their hard way, TCC is FAST as a compiler I mean, it one pass

TCC is “tiny”, it’s really tiny compiler which is not a toy, it fully support many corner cases in C, it produces a small executables, if you’re learning decompilation for example, it’s easy to use TCC when you need a small build-system-environment, for education purposes, also TCC uses in other languages and compilers (Nim for example) which translates their source code into C, also some OS uses TCC as a main compiler (DeforaOS, a nice little project, if I not wrong), TCC is a good example if you want to learn bitwise operations in their hard way, TCC is FAST as a compiler I mean, it one pass compiler without deep optimizations stages, TCC sources is a good example how someone thinks like a genius, it has an embedded preprocessor written from scratch, and LINKER with output formats pe32 and pe64 for windows, it has a bunch of std-headers from the box and a bunch of headers for win-api, it can interpret C-files, it has builtin ASM inside (unbelivable), it injects debug markers in output exe-file, it's easy to use it, and it’s a compiler with charisma.

PS. It’s a good example, how may be written preprocessor+compiler+optimizer+linker+interpreter+assembler, and all of them in 25000 SLOC.

Profile photo for Quora User

Windows version does not matter cause Windows is accessed via APIs which are part of H files (and lib files to preload DLLs).

What matters is code generation for CPU used. If still running Win 98 I will suppose it uses older CPU, like Pentium 1, 2. In those CPUs lot of extensions, instructions, are unavailable, eg AVX.
CPU affects compiler code generation as well as compiler libraries used, eg string copy. Eg in Visual Studio usually default CPU is “generic type” which is x86 compatible.
Some code generated using GCC (latest versions) when AVX is enabled use AVX for memory copy and even optimiz

Windows version does not matter cause Windows is accessed via APIs which are part of H files (and lib files to preload DLLs).

What matters is code generation for CPU used. If still running Win 98 I will suppose it uses older CPU, like Pentium 1, 2. In those CPUs lot of extensions, instructions, are unavailable, eg AVX.
CPU affects compiler code generation as well as compiler libraries used, eg string copy. Eg in Visual Studio usually default CPU is “generic type” which is x86 compatible.
Some code generated using GCC (latest versions) when AVX is enabled use AVX for memory copy and even optimizes for loops which set it.

Profile photo for Petr Skocik

I’d look for the culprit inside your source file (maybe you’re statically allocating a big array?).

Translating and linking a simple raw-systemcall hello world on x86–64 Linux gets me a static executable of about 8KiB (2 segments (rodata + text), 1 page each).

A C hello world using libc yields a twice as largge (about 16KiB) dynamically-linked executable.

Profile photo for Quora User

I fear you misunderstand all of the above.

C, and C++ are two sets of human-readable languages. In order for a human to tell a computer how to create a program to run on a computer.

A Docker image is a set of programs to run on a computer. Just in a preloaded set of collaborative programs. Be they made using C, or C++ or Python, or whatever else, is immaterial. In fact, nearly all those programs are very likely created using either C or C++.

It would definitely not preclude a data centre using programs created in those languages. Docker just gives an alternative method for running the programs af

I fear you misunderstand all of the above.

C, and C++ are two sets of human-readable languages. In order for a human to tell a computer how to create a program to run on a computer.

A Docker image is a set of programs to run on a computer. Just in a preloaded set of collaborative programs. Be they made using C, or C++ or Python, or whatever else, is immaterial. In fact, nearly all those programs are very likely created using either C or C++.

It would definitely not preclude a data centre using programs created in those languages. Docker just gives an alternative method for running the programs after they’re already created using any language, just like running them bare metal or inside a full VM would. Makes no difference.

The concepts are perpendicular, compatible, not competitors of one another. Both can happen at the same time. Both can be changed independent of one another. They don’t have an effect on each other.

Profile photo for Reini Urban
  • gcc produces better code, whilst icc produces the best code.
  • clang produces better diagnostics, which can lead to much better code in the end, by fixing more bugs and adding more missed optimizations. But both are playing the catch-up game there.
  • newer clang-5+ has better compile-time check support, which can lead with object_size checks to much better code with most constexpr’s, even with C. In certain projects (e.g. a libc rurban/safeclib) clang can be then at least 2x faster than gcc.
  • clang has better tooling support, e.g to integrate C++ into emacs or vi.
  • gcc has stable JIT support. clang’s JI
  • gcc produces better code, whilst icc produces the best code.
  • clang produces better diagnostics, which can lead to much better code in the end, by fixing more bugs and adding more missed optimizations. But both are playing the catch-up game there.
  • newer clang-5+ has better compile-time check support, which can lead with object_size checks to much better code with most constexpr’s, even with C. In certain projects (e.g. a libc rurban/safeclib) clang can be then at least 2x faster than gcc.
  • clang has better tooling support, e.g to integrate C++ into emacs or vi.
  • gcc has stable JIT support. clang’s JIT support changed 3x in the past, but is still in the lead. icc has no jit support.
  • gcc supports much more older platforms, whilst only clang support the new GPU and APU platforms.
  • clang compiles faster. fastest would be zapcc, a commercial clang derivate. And of course tinycc
Profile photo for Jack Miller

Yes, you can use either. Muddle through a chroot tutorial to create a skeleton directory containing the new glibc, then start up your exec inside the chroot. Alternatively, it's quicker to create a container, but you end up with a new IP / what is essentially a new box. If it's a pain to factor that into your inventory system or documentation, it might be the deciding factor. Also you might run into this "somehow can't be upgraded" problem again.

You can also use the environment variable LD_LIBRARY_PATH with your binary and point it where the newer glibc is, but that's kinda hokey unless it's a

Yes, you can use either. Muddle through a chroot tutorial to create a skeleton directory containing the new glibc, then start up your exec inside the chroot. Alternatively, it's quicker to create a container, but you end up with a new IP / what is essentially a new box. If it's a pain to factor that into your inventory system or documentation, it might be the deciding factor. Also you might run into this "somehow can't be upgraded" problem again.

You can also use the environment variable LD_LIBRARY_PATH with your binary and point it where the newer glibc is, but that's kinda hokey unless it's a one-off

Profile photo for David Brower
  1. You’re on a system that doesn’t have enough memory to run current versions of GCC.
  2. You run things through multiple compilers to see what warnings and errors come out.
  3. You like insanely fast compilation.
  4. You’re embedded in something else and don’t want to drag a GCC around with you.
Profile photo for Michael Veksler

Like Quora User I am getting 5032 bytes with gcc-5.0 on a x86_64 linux, but when I link statically:
g++5.0 -static -Os -s t.cpp
I am starting to get a 1.3MiB executable.

I suspect that you are getting 0.5MiB on Windows because your compliers are linking statically or they bring some extra baggage. To test this hypothesis I have tried it on Cygwin-x86_64 GCC-4.9 on which the executable is only slightly larger: 8704 bytes. So it does not look like the default compiler config does this.

Next, I tried to link statically on cygwin using the -static flag. The result is surprisingly similar to you

Like Quora User I am getting 5032 bytes with gcc-5.0 on a x86_64 linux, but when I link statically:
g++5.0 -static -Os -s t.cpp
I am starting to get a 1.3MiB executable.

I suspect that you are getting 0.5MiB on Windows because your compliers are linking statically or they bring some extra baggage. To test this hypothesis I have tried it on Cygwin-x86_64 GCC-4.9 on which the executable is only slightly larger: 8704 bytes. So it does not look like the default compiler config does this.

Next, I tried to link statically on cygwin using the -static flag. The result is surprisingly similar to yours: 576KiB. Static linking brings in a lot of things you don't really need.

Next, I check mingw for x86_64, and that takes 16KiB with default parameters. This is pretty bad but not as bad as you see. And with -static it also takes 585KiB.

So I guess that in your case, your setup is somehow linking in static libraries instead of using DLLs. I think that the size you see is a constant value added to all executables. What I am trying to say that increasing your trivial program to a 1000 lines program, the source code increase will not have a dramatic impact on your 500KiB executables since most of it is a C++ library stuff.

Profile photo for David Kra

No. Big data centers are not moving their code bases, which are almost entirely not in C C++: neither to docker containers nor to virtual machines.

(The code base is the set of source code files used by a team, project, application, or business process.)

For a data center, the source code files in the data center’s code base are mostly shell scripts, sets of utility control statements, configuration files, job control language files, possibly performance report outputs for comparison purposes, etc. Data centers have very few C C++ files.

Data centers are moving their code bases to GIT, SUBVERSION

No. Big data centers are not moving their code bases, which are almost entirely not in C C++: neither to docker containers nor to virtual machines.

(The code base is the set of source code files used by a team, project, application, or business process.)

For a data center, the source code files in the data center’s code base are mostly shell scripts, sets of utility control statements, configuration files, job control language files, possibly performance report outputs for comparison purposes, etc. Data centers have very few C C++ files.

Data centers are moving their code bases to GIT, SUBVERSION, and other text file control systems.

Profile photo for Anoop Aryal

It's all relative. Most C programmers complain about C++ being bloated. The same could be argued about a C program. See A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux for a decent exposition on what goes on under the hood. It's about a C program, but should give you a good reference point to then use your imagination for what happens with a C++ program.

Profile photo for Braden Best

Contrary to the common misconception, GCC actually stands for the GNU Compiler Collection, not GNU C Compiler. If configured correctly, you can use it to compiler even more languages, but if I’m not mistaken, GCC comes standard with a C compiler and a C++ compiler.

If you look at the man page, you’ll see the standards GCC supports:

c89

iso9899:1990

Support all ISO C90 programs (certain GNU extensions that conflict with ISO C90 are disabled). Same as -ansi for C code.

iso9899:199409

ISO C90 as modified in amendment 1.

c99

c9x

iso9899:1999

iso9899:199x

ISO C99. Note that this standard is not yet fully supp

Contrary to the common misconception, GCC actually stands for the GNU Compiler Collection, not GNU C Compiler. If configured correctly, you can use it to compiler even more languages, but if I’m not mistaken, GCC comes standard with a C compiler and a C++ compiler.

If you look at the man page, you’ll see the standards GCC supports:

c89

iso9899:1990

Support all ISO C90 programs (certain GNU extensions that conflict with ISO C90 are disabled). Same as -ansi for C code.

iso9899:199409

ISO C90 as modified in amendment 1.

c99

c9x

iso9899:1999

iso9899:199x

ISO C99. Note that this standard is not yet fully supported; see <Status of C99 features in GCC> for more information. The names c9x and iso9899:199x are deprecated.

gnu89

GNU dialect of ISO C90 (including some C99 features). This is the default for C code.

gnu99

gnu9x

GNU dialect of ISO C99. When ISO C99 is fully implemented in GCC , this will become the default. The name gnu9x is deprecated.

c++98

The 1998 ISO C ++ standard plus amendments. Same as -ansi for C ++ code.

gnu++98

GNU dialect of -std=c++98. This is the default for C ++ code.

c++0x

The working draft of the upcoming ISO C ++ 0x standard. This option enables experimental features that are likely to be included in C ++ 0x. The working draft is constantly changing, and any feature that is enabled by this flag may be removed from future versions of GCC if it is not part of the C ++ 0x standard.

gnu++0x

GNU dialect of -std=c++0x. This option enables experimental features that may be removed in future versions of GCC .

The important thing to understand here is that the program, gcc, is a front-end. When invoked without an argument explicitly telling it what types of files it’s working with (e.g. ‘gcc -x c’ or ‘gcc -std=gnu++11’), it will attempt to figure that out on its own by looking at the file extensions.

So if it sees a .c or .cpp file, it will choose the corresponding C or C++ compiler (+ default standard) to compile it with. If it sees a .s, .asm or other type of assembly file, it will call the assembler. If it sees a list of .o files, it will call the linker.

‘g++’ is functionally identical to ‘gcc -x c++’.

Profile photo for Adrien Lucas Ecoffet

★★★★

A very solid compiler, probably the one most used throughout the world, and certainly the one I am most familiar with.

However, it compiles relatively slowly (certainly not as quickly as clang), and does not produce the most optimized code on the market (icc and even the Microsoft compiler generally produce faster executables).
Its error messages are quite typical, but clang has proven that we could legitimately ask for better:
gcc

  1. hello.c: In function ‘int main()’: 
  2. hello.c:8: error: expected `;' before ‘return’ 



clang

  1. hello.c:7:27: error: expected ';' after expression 
  2. printf("hello, world\ 

★★★★

A very solid compiler, probably the one most used throughout the world, and certainly the one I am most familiar with.

However, it compiles relatively slowly (certainly not as quickly as clang), and does not produce the most optimized code on the market (icc and even the Microsoft compiler generally produce faster executables).
Its error messages are quite typical, but clang has proven that we could legitimately ask for better:
gcc

  1. hello.c: In function ‘int main()’: 
  2. hello.c:8: error: expected `;' before ‘return’ 



clang

  1. hello.c:7:27: error: expected ';' after expression 
  2. printf("hello, world\n") 
  3. ^ 
  4. ; 


One thing which it definitely does better than the rest of the competition is implementing new language features quickly (C99 and more recently C++0x/11).

Profile photo for Philippe Dunski

Hello,

Of course, you can.

You can with gcc, but you can too with MsVC, clang and … any compiler you could consider to use because it’s the foundation of the “modular” compilation.

Basically, using multiple libraries will affect size and performance of the final executable nor more nor less than if you had yourself developed the libraries with the same quality.

I mean: libraries are just “bunch of functionalities” whose are “well working together”.

Those functionalities can be developed in “more or less efficient” way. And the developer of those functionalities can be … you or “someone else”, it do

Hello,

Of course, you can.

You can with gcc, but you can too with MsVC, clang and … any compiler you could consider to use because it’s the foundation of the “modular” compilation.

Basically, using multiple libraries will affect size and performance of the final executable nor more nor less than if you had yourself developed the libraries with the same quality.

I mean: libraries are just “bunch of functionalities” whose are “well working together”.

Those functionalities can be developed in “more or less efficient” way. And the developer of those functionalities can be … you or “someone else”, it doesn’t care :

If those functionalities have been developed in an efficient way, the impact of using them will be “as much restricted as possible”

But, if those functionalities have been developed in an inefficient way, the impact of using them could be catastrophic.

If you can develop the same functionalities with the same efficiency as the library you are using, you will get exactly the same end result.

The only thing which has some impact on the final result’s size or performance is the kind of library you consider to use:

If you consider to use a static library, all CPU instructions making used functionalities available in the program will be put in the final executable file.

If you consider to use a shared library, all CPU instructions making functionalities will be made available through an external executable file ( typically *.so file on *nix system or *.dll file on windows system) and your final executable file’s will be smaller.

Gcc has always produced faster code for at least 15 years. In fact, it is the Intel compiler which has caught up in the most recent version. I got faster (10-20%) results with icc on an abstract game minimax AI bot back then (i.e. something similar to a chess engine). Even more so when taking advantage of PGO.

Profile photo for Alexis Ryan

I would guess NASM is creating an initialized data segment (you probably told it to by using .data) and must include the initial values for everything even unused space in the data segment of the executable but gcc will be using an uninitialized (.bss) data segment and stores nothing in the executable except the segment size and linear address. I also suspect the NASMs default alignment is probably larger than gccs too. Instruct gcc to generate an assembly language listing of your c program to see what it is doing differently.

Gcc also likely allows the linker to rearrange the memory layout to

I would guess NASM is creating an initialized data segment (you probably told it to by using .data) and must include the initial values for everything even unused space in the data segment of the executable but gcc will be using an uninitialized (.bss) data segment and stores nothing in the executable except the segment size and linear address. I also suspect the NASMs default alignment is probably larger than gccs too. Instruct gcc to generate an assembly language listing of your c program to see what it is doing differently.

Gcc also likely allows the linker to rearrange the memory layout to reduce unused space in the data segment. While NASM wouldn’t allow this.

Profile photo for Amarin Phaosawasdi

(A year and a half later... :))

Another thing that might factor in is C++11 support.

For example, as of now (May 24, 2012), clang 3.1 supports strong compare and exchange (http://clang.llvm.org/cxx_status.html) while gcc doesn't support it yet (http://gcc.gnu.org/projects/cxx0x.html).

Other advantages:

Since it's written more modularly, down the road, bug fixes and improvements *should* be released quicker. (This is just my speculation.)

Chromium is already using clang as its default compiler for Mac. (http://code.google.com/p/chromium/wiki/Clang). This implies that it will at least be heavily test

(A year and a half later... :))

Another thing that might factor in is C++11 support.

For example, as of now (May 24, 2012), clang 3.1 supports strong compare and exchange (http://clang.llvm.org/cxx_status.html) while gcc doesn't support it yet (http://gcc.gnu.org/projects/cxx0x.html).

Other advantages:

Since it's written more modularly, down the road, bug fixes and improvements *should* be released quicker. (This is just my speculation.)

Chromium is already using clang as its default compiler for Mac. (http://code.google.com/p/chromium/wiki/Clang). This implies that it will at least be heavily tested to some extent.

Clang is built on LLVM, and not only is LLVM being used a lot in current research (search for "site:edu llvm" in google), but also some cool tools are based on LLVM (https://github.com/kripken/emscripten). So your code might get these benefits "for free".

Profile photo for Quora User

“It can create 32-bit OR 64-bit binaries, for any version of Windows since Windows XP.”

About | tdm-gcc
GCC compiler, Windows-friendly.
Profile photo for Anton Carver

I assume you mean G++ (not GCC which is either the C compiler or the whole compiler system).

G++ still tends to generate slightly faster code for most cases. Clang tends to be much stricter about conformance to the standard (though G++ seems to be getting better). Clang / LLVM is generally more tool friendly, if you are interested in manipulating C++ code in a tool. GCC is GPL and Clang is BSD License.

There isn’t much in it really, they are both pretty good.

Profile photo for Ferenc Valenta

“What is the reason for the long compilation time of small projects using GCC (C/C++)?”

Weird question. GCC is not slow at all. It’s usually among the fastest compilers. We’re using a lot of cross-compilers for our automotive microcontroller targets, and I’m regularly checking the build performance of our AUTOSAR solutions. I know only GCC-based commercial compiler that’s really slow. On the other hand, all the top places are taken by GCC and other GCC-based commercial solutions.

If you’re not satisfied with its performance, try another compiler, check your antivirus settings, check how many fil

“What is the reason for the long compilation time of small projects using GCC (C/C++)?”

Weird question. GCC is not slow at all. It’s usually among the fastest compilers. We’re using a lot of cross-compilers for our automotive microcontroller targets, and I’m regularly checking the build performance of our AUTOSAR solutions. I know only GCC-based commercial compiler that’s really slow. On the other hand, all the top places are taken by GCC and other GCC-based commercial solutions.

If you’re not satisfied with its performance, try another compiler, check your antivirus settings, check how many files are there in that small project and so on. Your project might inherently build slow due to the technologies used in the code, but there might be options to speed up the build process.

Profile photo for Naeem Ullah

A little digging on the internet will get you to GCC compiler (g++) as the best one. It has support for all platforms (windows, linux unix and others) as well as support for all IDEs (QtCreator, Kdevelop, Eclipse, NetBeans, Code::Blocks, Geany). It has GPLV3 license. The GNU General Public License is a widely used free software license, which guarantees end users the freedom to run, study, share and modify the software. Therefore you own the code and the binary that you develop using this compiler. It has the latest C++ coding libraries support and by latest I mean C++17 - Wikipedia.

Happy Codi

A little digging on the internet will get you to GCC compiler (g++) as the best one. It has support for all platforms (windows, linux unix and others) as well as support for all IDEs (QtCreator, Kdevelop, Eclipse, NetBeans, Code::Blocks, Geany). It has GPLV3 license. The GNU General Public License is a widely used free software license, which guarantees end users the freedom to run, study, share and modify the software. Therefore you own the code and the binary that you develop using this compiler. It has the latest C++ coding libraries support and by latest I mean C++17 - Wikipedia.

Happy Coding.

Profile photo for Jonathan Briggs

Yes. You want to use the LTO features.

Set up a Makefile like this:

  1. # Makefile 
  2.  
  3. LTOFLAGS += -flto -fno-fat-lto-objects 
  4. OPTFLAGS += -O3 -march=native $(LTOFLAGS) 
  5. FLAGS += -Wall -W -pedantic -Winvalid-pch -g $(OPTFLAGS) -MMD $(EXTRA) 
  6. FLAGS += -fPIC -fPIE -fstack-protector-strong 
  7. CFLAGS = $(FLAGS) -std=c18 
  8. CXXFLAGS = $(FLAGS) -std=c++17 
  9. LDFLAGS += $(LTOFLAGS) 
  10.  
  11. c-cpp-string-api-test: c-cpp-string-api.o c-cpp-string-api-test.o 
  12. $(CXX) $(CXXFLAGS) $(LDFLAGS) $^ -o $@ 
  13.  
  14. -include *.d 
  15.  
  16. clean: 
  17. rm -f *.o *.d c-cpp-string-api-test 
  18.  
  19. .PHONY: clean 

Adjust it to your personal taste of course. The important parts are the LTOFLAGS

Yes. You want to use the LTO features.

Set up a Makefile like this:

  1. # Makefile 
  2.  
  3. LTOFLAGS += -flto -fno-fat-lto-objects 
  4. OPTFLAGS += -O3 -march=native $(LTOFLAGS) 
  5. FLAGS += -Wall -W -pedantic -Winvalid-pch -g $(OPTFLAGS) -MMD $(EXTRA) 
  6. FLAGS += -fPIC -fPIE -fstack-protector-strong 
  7. CFLAGS = $(FLAGS) -std=c18 
  8. CXXFLAGS = $(FLAGS) -std=c++17 
  9. LDFLAGS += $(LTOFLAGS) 
  10.  
  11. c-cpp-string-api-test: c-cpp-string-api.o c-cpp-string-api-test.o 
  12. $(CXX) $(CXXFLAGS) $(LDFLAGS) $^ -o $@ 
  13.  
  14. -include *.d 
  15.  
  16. clean: 
  17. rm -f *.o *.d c-cpp-string-api-test 
  18.  
  19. .PHONY: clean 

Adjust it to your personal taste of course. The important parts are the LTOFLAGS which are needed in the compilation flags and the linker flags.

The “no-fat-lto” flag disables the default of building object files with both standard binary instructions and LTO instructions, and only builds LTO instructions. GCC calls this GIMPLE and it is a GCC internal format only used by GCC.

The final link step will take the individual LTO compilation stages, optimize it, and build the final program. This will optimize the entire program. It will inline everything it can and it will not export any visible symbols unless you use GCC attributes to make them “externally_visible”.

Profile photo for Chris Reid

Simple answer — static linking puts the binary libraries of functions into your executable. All of them. The program does not depend on external libraries, it will run on most version of the Operating system.

That said, most operating systems of course do not allow you to put ALL the libraries into your program anymore. So what we are talking is embedding the user libraries beyond libc, such as libjpg or libgtk, etc. The binary library code is linked in and is present in the executable file.

The advantage is that if library changes, or is not present on a system, the program will run fine, becau

Simple answer — static linking puts the binary libraries of functions into your executable. All of them. The program does not depend on external libraries, it will run on most version of the Operating system.

That said, most operating systems of course do not allow you to put ALL the libraries into your program anymore. So what we are talking is embedding the user libraries beyond libc, such as libjpg or libgtk, etc. The binary library code is linked in and is present in the executable file.

The advantage is that if library changes, or is not present on a system, the program will run fine, because it has the functions and other stuff with it already.

The disadvantage is large memory footprint, large file size, and no fixing of bugs, no updates of the library code without recompiling.

Dynamic library linking ( shared libraries) loads up the libraries into RAM via a kernel call, and the program gets live links to them taht it can use as if it had the library in its executable.

The kernel can manage sharing of the library and load and unload it as needed.
This save space for the program, if more than one program using it is loaded, and eliminates the need for the full library to be linked into the executable.

Shared libraries have been default for many years now, except for special utilities and embedded systems, that have bare-bones operating systems.

Some “Repair OS” distributions have statically compiled programs for the repair of broken systems.

Most OS kernels have their own shared libraries they use, as in loadable device drivers, kernel extension modules, etc.

If you find your program is compiling in a large number of related object files (.o), consider making the .o files into a shared library (.so) and compiling with the -shared
option.
Your executable will run as before but be much smaller. Make sure you read the docs and how and where to put such libraries so they will be found by the kernel when your program launches. Libraries that update often are good candidates for shared libraries as well.

Profile photo for Dale Gulledge

This was a big naming mistake. At first, there was gcc, which was just a C compiler. The name stood for “GNU C Compiler” as far as I know. But new front ends were written for it that parsed C++, Fortran and various other languages. In an effort to acknowledge the shared back end code, the whole thing was named the GNU Compiler Collection, or GCC. The command to run the GNU C Compiler is still gcc, of course. So, the distinction is now that gcc is the C compiler, and GCC is the set of compilers. If you want to compile other languages, there are separate commands for each of them, such as g++ to

This was a big naming mistake. At first, there was gcc, which was just a C compiler. The name stood for “GNU C Compiler” as far as I know. But new front ends were written for it that parsed C++, Fortran and various other languages. In an effort to acknowledge the shared back end code, the whole thing was named the GNU Compiler Collection, or GCC. The command to run the GNU C Compiler is still gcc, of course. So, the distinction is now that gcc is the C compiler, and GCC is the set of compilers. If you want to compile other languages, there are separate commands for each of them, such as g++ to compile C++, although I think gcc will also compile C++ code. In practice, just use the command for the language you want.

Profile photo for Simon Kinahan

GCC compiles itself - no other compiler can do it. You either have to compile the compiler on another system where gcc is already installed, or bootstrap it using another compiler. GCC uses a three phase bootstrap process where first you use another compiler to build a mini GCC that's designed to be easy to compile but can compile the full GCC code, then you use the mini GCC to build a real GCC. This is fully functional, but not very fast because it was built with the mini GCC which isn't a very good compiler. In the last phase, the full but not very efficient gcc is used to build GCC. This is

GCC compiles itself - no other compiler can do it. You either have to compile the compiler on another system where gcc is already installed, or bootstrap it using another compiler. GCC uses a three phase bootstrap process where first you use another compiler to build a mini GCC that's designed to be easy to compile but can compile the full GCC code, then you use the mini GCC to build a real GCC. This is fully functional, but not very fast because it was built with the mini GCC which isn't a very good compiler. In the last phase, the full but not very efficient gcc is used to build GCC. This is a fully functional compiler built with a fully functional compiler, so it's both efficient and able to compile other code efficiently

About · Careers · Privacy · Terms · Contact · Languages · Your Ad Choices · Press ·
© Quora, Inc. 2025