I've been trying to compile a simple multithreaded piece of code I found online in an effort to learn how to multithread.
To run this piece of code I need to use the compiler flags: -pthread and -std=c++0x.
But whenever I try to add the flags the build log doesn't show them being used.
I've tried some generic tips online to get these to work, but none of them worked. Can someone help?
I've tried other advice online to add compiler flags to code blocks, but when I do that and check the build log none of them appear.
Because This Question was marked as Duplicate, even if doesn't have to do with it, because there is about Linker Flag and here is about Compiler Flags, I will post My answer HERE.
You will have to go to Settings -> Compiler... and next you'll have to click on Linker Settings TAB.
On the right side you will see Other Linker Options.
There you have to type -lpthread and press OK.
You may need to click on rebuild after that.
Open your project and then go Project > Build Options > Compiler Flags .
You can tick boxes in the "Compiler Flags" tab, and you can write other options in the "Other Options" tab.
Do one or the other, e.g. don't tick the "-std=c++98" box and also put "-std=c++11" in the Other Options. This will end up in both options being passed to the compiler.
Another option instead of using the "other options" is to create a custom compiler flag. So in addition to a compiler flag, you can specify a linker flag. In the case of the -pthread (which I also was having trouble with) it looked like it needed the linker flag as well, as mentioned by Michi
One can create a new compiler flag by right clicking and selecting the new option
add options: menu->project->properties->Build targets tab->Build options button
Related
Using avr-gcc and attempting to reduce size of binary using -ffunction-sections and -fdata-sections when compiling and linking with --gc-sections. The .lds file contains nothing:
SECTIONS
{
}
This error occurs when partial linking many .o's into a .a, which will then be used later to complete the build.
I've read through some other posts that discuss these options, but nothing that clarifies the ENTRY() issue. Their doesn't seem to be a need for it at the partial stage before trying to reduce code size(pre-existing linker script clearly doesn't use it).
Documentation states : --gc-sectionts
"This option can be set when doing a partial link (enabled with option '-r'). In this case the root of symbols kept must be explicitly specified either by an '--entry' or `--undefined' option or by a ENTRY command in the linker script."
This is where I'm lost. Would greatly appreciate some more explanation of how to use --undefined, --entry, or ENTRY cmd in linker script to resolve this issue.
I had a similar issue and gave up. I ended up compiling with the -fwhole-program option enabled which significantly reduced the size of my bootloader.
I'm trying to compile a C program using libxml2 in Eclipse. It seems like my code doesn't have problems, but there are errors when I build my project.
The error output is in this screenshot: https://drive.google.com/file/d/0BwV-0_2diIaaQlZHM2Fwa2R0LWc/edit
Before this error, I had an “Undefined reference to” error, but it was because I forgot to link the library libxml2. Now it's the problem in the screenshot. I don't what to do.
[EDITED]
I solved my problem I just need to put -nostartfiles in the linker flags.
I solved my problem I just need to write -nostartfiles in the Linker Flags box :D
To find "Linker Flags" box go to Your Project > Properties > C/C++Build > Settings > GCC C Linker > Miscellaneous
That's it.
Thanks for help.
I don't think your solution is acceptable, I think it will lead to the same problem when your project is executed in other environment (another eclipse configuration, running it from console, etc)
That error occurs when you have defined the same function more than one time in your project, and I bet it's because you have defined the same function you already had in a library.
For example, if I have lib1.h with a function called hello() and then write the same function in your main.c (having that library linked) that problem will occur.
In fact, in your image, I can see "multiple definition of __data_start"
So I think you just have to change the problematic function name and it will be fixed.
In addition, this problem will be caused if you include the same library more than once in your program, but it can be solved using preprocessor (if you are interested in this, google it, since it would be off-topic and make my answer too long)
This is my first time of trying to develop with C programming language. I tried installing codeblock on my window 8 operating system, but whenever I run the codeblock program I get this error in the image below
I installed codeblock hopping that it would install the compiler alongside, but I was disappointed. I do not know how to install the standalone compiler, I checked it up online, but I really do not know from where to start, and I do not know if the problem is with my system. I would appreciate help on how to make my codeblock work properly or any other suggestions. Thanks all.
When running CB for the first time, you are prompted with a "Compiler auto-detection" dialog/window.
It looks like you chose the WRONG COMPILER -> GCC for MSP430 micro controller!
Correct that to GCC/MinGW
EDIT - 1: Its usually the first option on the "Compiler auto-detection" dialog
EDIT - 2
I think you may also have selected the wrong compiler for your CB project
For C project, Follow these steps:-
Create a new project -> Console application for C/C++,
Skip the first page, click next
Provide a title & path, click next
at compiler selection screen, select "GNU GCC Compiler" instead of "GNU GCC Compiler for MSP430"
The compiler might not be included in the Code::Blocks you downloaded (if you got codeblocks-12.11-setup.exe). There's another downloadable binary (codeblocks-12.11mingw-setup.exe) that includes the MinGW environment with the GNU GCC compiler. You might want to try that one.
Step-1 : Visit www.mingw.org/
Step-2 : Download and install all package.(Specially mark the the file starting from mingw)
Step-3 : Goto to installation and Apply Changes.
Step-4 : Now open your code block
Step-5 : Goto to Setting->Compiler
Step-6 : Now click toolchain executable AND SELECT GNU GCC COMPILER
Step-7: Click autodetect and then OK
I hope this will definitely work out, All the best
Just goto setting > compiler and click on "restore default" . Then yes and ok .Done . I think it will never occur the error.
I'm writing C code and was initially using the gcc checker. Errors were reported in the C file. Lots of errors that didn't matter were being reported due to, for instance, no include directory switches on the gcc command line in the checker. Because we're using icc and it feels unwieldy to setup all of the parameters that are already setup in our makefile, I decided to switch over to using the make checker.
Upon switching to the make checker, I did not get any results. Looking at the makeprg command in make.vim, it is make -sk. I realized that our makefile was not setup to do syntax checking, so I created a new target called syntax_check that added the -fsyntax-only and -c flags. I then changed the make.vim makeprg command to make -sk clean syntax-check so that the appropriate target is run.
When I save the file I watched top in another window and saw that the build is occuring. However, I'm still getting no errors. By this, I mean I don't see the green sidebar indicating lines that did not have errors. Running :Errors does not bring up the location list.
Any ideas? And is my understanding of how to look at the generated errors in syntastic wrong (which it may very well be)?
As a side note for the question here, I've also got this question in on the Syntastic github page here.
It turns out that the errorformat was wrong for handling icc. This, of course, makes total sense.
The errorformat for icc that I've got so far is:
let errorformat = '%W%f(%l): %tarning #%n: %m,%E%f(%l): %trror: %m'
I will add more to this as I find errors that aren't covered by this format or find that I need different formatting.
(I'm not sure if "flag" is the word I'm looking for, but I'll explain it.)
I am trying to compile a program that uses the GMP big number library. But to be able to compile with GMP, I have to add -lgmp to the end of the command. For example, if I want to compile "program.c", I have to type gcc program.c -lgmp. This is easy from the command line, but I don't see how to do it in Xcode. How can I add the lgmp flag while using Xcode?
Right-click the target in the Xcode Groups and Files list and select Get Info from the contextual menu. In the Build tab, type linker into the search field and then locate the Other Linker Flags item.
Double-click the Other Linker Flags item and add -lgmp.
Maybe this helps:
You can also open the active target's preferences, and click the "General" tab. You can add the library to be linked inside that tab, in the "Linked Libraries" section at the botton.
Taken from http://www.soulstorm-creations.com/PROJECT_SOULSTORM_2_0/programming-articles/installing-portable-libraries-on-os-x.html
You can just open the folder containing libgmp.a on your system (/usr/local/lib/ for a default install), and drag the library out of the folder onto the target that you want it to get linked into. There are several other ways as well, such as the one suggested by Zitrax.