|
So I went to Project Properties -> C/C++ Build -> Settings -> MCU G++ Linker and replaced the following Command line pattern:
${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS} with
arm-none-eabi-g++ -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -T"" -Wl,-Map,output.map -Wl,--gc-sections -fno-exceptions -fno-rtti -o "MyProject.elf" @"objects.list" -lm When I build the project and look inside the console window, I see the following:
Invoking: MCU G++ Linker
arm-none-eabi-g++ -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -T"" -Wl,-Map,output.map -Wl,--gc-sections -fno-exceptions -fno-rtti -o "MyProject.elf" @"objects.list" -lm -lm
c:/ac6/systemworkbench/plugins/fr.ac6.mcu.externaltools.arm-none.win32_1.17.0.201812190825/tools/compiler/bin/../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/bin/ld.exe: cannot open linker script file -Wl,-Map,output.map: No such file or directory What did I do wrong?
|
|
|
|
|
arnold_w wrote: What did I do wrong? Nothing that I can see. I just did a build with -Wl,-Map,output.map and it worked fine. But the error message you have suggests that the linker is trying to read -Wl,-Map,output.map as a script file for some reason. I am not sure whether the MCU g++ linker is significantly different from the standard ld linker , but you may want to check the documentation.
|
|
|
|
|
It's probably a stupid question, but is there any way to make anonymous function usage like that compile inside a file with .c (not .cpp) extension? I know I'm allowed to put snippets of C-code inside a C++ file, but I suppose the opposite isn't possible (not even with clever macros)?
|
|
|
|
|
i'm just testing to run prog using parameters, but why i got error when debugging?
screenshot[^]
this is my code:
#include <iostream>
int main (int argc, char * argv []) {
if (argc > 0) {
std::cout << *argv[1] << std::endl;
}
std::cin.ignore(std::numeric_limits<int>::max(), '\n');
std::cout << "press ENTER to close program.";
std::cin.get();
return 0;
}
|
|
|
|
|
If you call the program via:
myprog.exe
then argc will equal 1 , and argv[1] will not exist, hence the exception. Remember, array indexes start from zero, not one.
|
|
|
|
|
i know, but how to respond users if there's argument(s) submitted?
|
|
|
|
|
You have two choices:
1. Your program needs specific argument values which you must check by iterating over the items in argv . The actual number and type is for you to decide.
2. Your program does not accept command line arguments in which case you just ignore them. You may wish to display a warning message if argc is greater than 1.
|
|
|
|
|
1. you mean like loop? i tried this but still error:
#include <iostream>
int main (int argc, char * argv []) {
int itr = 0;
if (argc > 0) {
while (itr <= argc) {
std::cout << argv[itr] << std::endl;
++itr;
}
}
std::cin.ignore(std::numeric_limits<int>::max(), '\n');
std::cout << "press ENTER to close program.";
std::cin.get();
return 0;
}
2. so how to make my program accept argument(s)?
|
|
|
|
|
You did not mention what error you received, but I assume it is because you are still trying to access an item which does not exist. The values for argc and argv are as follows:
1. argv is an array of strings, which will always contain at least one item: the name of the executable that is used to initiate the program.
2. argc contains the number of items in the argv array. So it will always be at least 1.
Let's look at a couple of examples:
1. A simple command line call to run my program, which is called Test.exe produces the following:
C:\Users\user1\Documents\Code\C++>Test.exe
argc = 1
argv[0] = Test.exe
There are no input parameters, argc equals 1 as there is only one item in argv , and that is argv[0] which contains the program name. If I use the full path to run the program the output will be:
C:\Users\user1\Documents\Code\C++>C:\Users\user1\Documents\Code\C++\Test
argc = 1
argv[0] = C:\Users\user1\Documents\Code\C++\Test
If we add some parameters to the command line we will get something like
C:\Users\user1\Documents\Code\C++>Test.exe one two "three and a half"
argc = 4
argv[0] = Test.exe
argv[1] = one
argv[2] = two
argv[3] = three and a half
So argv now contains 4 items, the program name followed by each item that is separated by a space or tab. Not that argv[3] contains four words, since they were delineated by double quotes in the command line.
The code to list these values is as follows:
std::cout << "argc = " << argc << std::endl;
for (int i = 0; i < argc; ++i)
{
std::cout << "argv[" << i << "] = " << argv[i] << std::endl;
}
Generally you are not interested in the program name so you can start the above loop from 1 rather than 0.
The actual values in each parameter are for you to decide. You can use simple strings in a specific or random order, option letters or names preceded by single or double dashes or forward slashes:
Test check \foo\bar\filename.txt
Test -c C:\user1\Documents\file.jpg
Test --check somefilename
... etc.
|
|
|
|
|
this is really embarrassing! this was my mistake...
thank you very much! i just fix the code and now it's working![^]
this is the final test code:
#include <iostream>
int main (int argc, char * argv []) {
if (argc > 1) {
std::cout << argv[1] << std::endl;
}
std::cin.ignore(std::numeric_limits<int>::max(), '\n');
std::cout << "press ENTER to close program.";
std::cin.get();
return 0;
}
really appreciate your reply!!
|
|
|
|
|
|
what is best resource to learn python language
|
|
|
|
|
you know that this is C & C++ thread, right?
|
|
|
|
|
|
Try to Google with Python and tutorial.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
The C/C++/MFC forum, of course.
|
|
|
|
|
Can i Use C++ Progam to develop a Appliciton for Andriod?
|
|
|
|
|
What happened when you Googled for "C++ application development"?
|
|
|
|
|
Yes.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
|
Hi, How are you?...i hope you are doing fine... i want to ask is there any built in function to get on exact line in a file? Like:
FILE DATA:
1)Start
2)Mid
3)Username
4)END
i want to get the pointer of file handler on 3 so that i can read that specific line....
or Can we use Seekg.(); function in this case? Kindly help please
|
|
|
|
|
I don't know of such a function. If each line ends in an '\n' , you can use std::getline to read each one and count up to the line you want.
seekg moves by a specified number of characters, so it won't help unless lines are padded to a fixed length.
|
|
|
|
|
The simplest way to do this is to read the file line by line and check for the data that you are interested in. Remember a text file is just a stream of characters with no structure so you cannot easily use file positioning to get to a particular item.
|
|
|
|
|
If you have questions or comments then please use the Reply link, not the Email.
|
|
|
|
|
but i want to privately message you dont want leak my code please check the inbox kindly ... Thank you
|
|
|
|