Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Программирование под Unix/Linux > gcc


Автор: sergioK1 1.5.2011, 13:41
IDE моя компилит так 

gcc -O0 -Wall -c -std=c99 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"

и
gcc -O0 -g -c -std=c99 -MMD -MP -MF"src/sharedMemory.d" -MT"src/sharedMemory.d" -o"src/sharedMemory.o" "../src/sharedMemory.c"

что за флаги такие y gcc, нигде ничего найти не смог и для чего файлы с расширением d

Автор: bsa 3.5.2011, 12:11
d - от слова dependency - зависимость. таким образом создаются списки заголовочных файлов, используемых исходником, для отслеживания зависимости от них.

Автор: null56 3.5.2011, 15:42
Цитата(sergioK1 @  1.5.2011,  13:41 Найти цитируемый пост)
gcc -O0 -Wall -c -std=c99 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"

для начала man gcc, неужели там ничего не нашел...
цитирую оттуда

-O<число> - читается как "буква О нуль" (в твоем случае) - уровень оптимизации
-Wall - максимум ворнингов
-c - компилить smile
-std=<> - стандарт языка (в твоем случае расширение языка c99)
про различия -M, -MMD, -MP, -MF почитай в мане
http://linux.die.net/man/1/gcc

$@, $< - ответы тут http://www.tver.mesi.ru/e-lib/res/347/MAKE.htm
Цитата

$@
    Этот макрос заменяется на полное имя целевого файла; вычисляется только для явно заданных зависимостей.

$<
    Вычисляется только для подразумеваемых правил или для правила .DEFAULT. Этот макрос заменяется на имя файла, от которого по умолчанию зависит целевой файл. Так, в правиле .c.o макрос $< будет заменен на имя файла с расширением .c. Например, правило для изготовления оптимизированного об ектного файла из файла с расширением .c может быть таким: 


"$(@:%.o=%.d)" тут, затрудняюсь ответить, но это регулярное выражение отвечает за формирование имени конечной цели, подробнее наверное или в мане по make или того же gcc
может тут что есть
http://ftp.linux.kiev.ua/pub/docs/developer/tools/make.txt
но я полагаю, что имя целевого файла равно имени файла %.o и имени %.d, то есть имя как раз равно '%', не помню уже, поэтому пускай меня поправят

Добавлено через 45 секунд
-g - дополнительная информация для gdb

Автор: bsa 3.5.2011, 22:56
Цитата(man gcc)
       -M  Instead of outputting the result of preprocessing, output a rule
           suitable for make describing the dependencies of the main source
           file.  The preprocessor outputs one make rule containing the object
           file name for that source file, a colon, and the names of all the
           included files, including those coming from -include or -imacros
           command line options.

           Unless specified explicitly (with -MT or -MQ), the object file name
           consists of the name of the source file with any suffix replaced
           with object file suffix and with any leading directory parts
           removed.  If there are many included files then the rule is split
           into several lines using \-newline.  The rule has no commands.

           This option does not suppress the preprocessor's debug output, such
           as -dM.  To avoid mixing such debug output with the dependency
           rules you should explicitly specify the dependency output file with
           -MF, or use an environment variable like DEPENDENCIES_OUTPUT.
           Debug output will still be sent to the regular output stream as
           normal.

       -MF file
           When used with -M or -MM, specifies a file to write the
           dependencies to.  If no -MF switch is given the preprocessor sends
           the rules to the same place it would have sent preprocessed output.

           When used with the driver options -MD or -MMD, -MF overrides the
           default dependency output file.

       -MD -MD is equivalent to -M -MF file, except that -E is not implied.
           The driver determines file based on whether an -o option is given.
           If it is, the driver uses its argument but with a suffix of .d,
           otherwise it takes the name of the input file, removes any
           directory components and suffix, and applies a .d suffix.

           If -MD is used in conjunction with -E, any -o switch is understood
           to specify the dependency output file, but if used without -E, each
           -o is understood to specify a target object file.

           Since -E is not implied, -MD can be used to generate a dependency
           output file as a side-effect of the compilation process.

       -MMD
           Like -MD except mention only user header files, not system header
           files.

       -MT target
           Change the target of the rule emitted by dependency generation.  By
           default CPP takes the name of the main input file, deletes any
           directory components and any file suffix such as .c, and appends
           the platform's usual object suffix.  The result is the target.

           An -MT option will set the target to be exactly the string you
           specify.  If you want multiple targets, you can specify them as a
           single argument to -MT, or use multiple -MT options.

           For example, -MT '$(objpfx)foo.o' might give

                   $(objpfx)foo.o: foo.c

Автор: sergioK1 7.5.2011, 20:40
Цитата(bsa @ 3.5.2011,  21:56)
Цитата(man gcc)
       -M  Instead of outputting the result of preprocessing, output a rule
           suitable for make describing the dependencies of the main source
           file.  The preprocessor outputs one make rule containing the object
           file name for that source file, a colon, and the names of all the
           included files, including those coming from -include or -imacros
           command line options.

           Unless specified explicitly (with -MT or -MQ), the object file name
           consists of the name of the source file with any suffix replaced
           with object file suffix and with any leading directory parts
           removed.  If there are many included files then the rule is split
           into several lines using \-newline.  The rule has no commands.

           This option does not suppress the preprocessor's debug output, such
           as -dM.  To avoid mixing such debug output with the dependency
           rules you should explicitly specify the dependency output file with
           -MF, or use an environment variable like DEPENDENCIES_OUTPUT.
           Debug output will still be sent to the regular output stream as
           normal.

       -MF file
           When used with -M or -MM, specifies a file to write the
           dependencies to.  If no -MF switch is given the preprocessor sends
           the rules to the same place it would have sent preprocessed output.

           When used with the driver options -MD or -MMD, -MF overrides the
           default dependency output file.

       -MD -MD is equivalent to -M -MF file, except that -E is not implied.
           The driver determines file based on whether an -o option is given.
           If it is, the driver uses its argument but with a suffix of .d,
           otherwise it takes the name of the input file, removes any
           directory components and suffix, and applies a .d suffix.

           If -MD is used in conjunction with -E, any -o switch is understood
           to specify the dependency output file, but if used without -E, each
           -o is understood to specify a target object file.

           Since -E is not implied, -MD can be used to generate a dependency
           output file as a side-effect of the compilation process.

       -MMD
           Like -MD except mention only user header files, not system header
           files.

       -MT target
           Change the target of the rule emitted by dependency generation.  By
           default CPP takes the name of the main input file, deletes any
           directory components and any file suffix such as .c, and appends
           the platform's usual object suffix.  The result is the target.

           An -MT option will set the target to be exactly the string you
           specify.  If you want multiple targets, you can specify them as a
           single argument to -MT, or use multiple -MT options.

           For example, -MT '$(objpfx)foo.o' might give

                   $(objpfx)foo.o: foo.c

не понятно несколько моментов

1) как в мане(не в гугле) быстро найти место относящееся к нужным флагам, что-бы не читать 50 страниц про ARM, Preprocessor  и все остальное (что-то типо man gcc -MM ) 
2) почему Эклипсе под Линукс строит мэйк файл а под винду нет? и как это изменить в настройках среды (это не форум Эклипса но тем не менее ,в гугле искал ничего толкового не нашел)
3) Что делать с оптимизацией? , из каких соображений исходить устанавливая уровень ?
4) Для чего во многих IDE eсть Release mode & Debug mode ? если можно просто  добавить флаг - g ?? 

Автор: Фантом 7.5.2011, 21:19
Цитата(sergioK1 @  7.5.2011,  20:40 Найти цитируемый пост)

1) как в мане(не в гугле) быстро найти место относящееся к нужным флагам, что-бы не читать 50 страниц про ARM, Preprocessor  и все остальное (что-то типо man gcc -MM ) 

В man есть поиск. Нажимаете "/" и вводите то, что требуется найти. Переход к следующему вхождению - "n".

Автор: rsm 8.5.2011, 14:39
Цитата(sergioK1 @  7.5.2011,  22:40 Найти цитируемый пост)
Что делать с оптимизацией? , из каких соображений исходить устанавливая уровень ?

Зависит от проекта. Если нужен бинарник минимального размера - ставим -Os. Если требуется быстрая работа кода - манипулируем -On, n =~ [1..3]. Если нужна облегченная отладка - ставим -O0.

Цитата(sergioK1 @  7.5.2011,  22:40 Найти цитируемый пост)
Для чего во многих IDE eсть Release mode & Debug mode ? если можно просто  добавить флаг - g ??

Несколько моделей сборки крайне удобны:
а) когда есть части кода, регулируемого препроцессором;
б) когда один и тот же код собирается под разные архитектуры;
в) для тестовых веток;
г) для сборок с разными флагами (например, -O0 -g -pg - сборка бинарника без оптимизации, с отладочной информацией и информацией для профилирования);
д) когда собирается сразу несколько бинарников с разными опциями компиляции;
е) и прочая прочая...
Конечно, никто не запрещает тупо открывать настройки проекта, ставить флажки, компилить, открывать настройки, убирать флажки, компилить, открывать настройки, ставить флажки... smile

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)