object-files

Templated function being reported as “undefined reference” during compilation

孤街浪徒 提交于 2019-12-02 07:57:46
These are my files: --------[ c.hpp ]-------- #ifndef _C #define _C #include<iostream> class C { public: template<class CARTYPE> void call(CARTYPE& c); }; #endif --------[ c.cpp ]-------- #include "c.hpp" template<class CARTYPE> void C::call(CARTYPE& c) { //make use of c somewhere here std::cout<<"Car"<<std::endl; } --------[ v.cpp ]-------- class Merc {}; --------[ main.cpp ]-------- #include "c.hpp" #include "v.cpp" //#include "c.cpp" int main() { Merc m; C someCar; someCar.call(m); }//main I'm able to generate ".o" files for all the above files, with the command g++ -c main.cpp and g++ -c c

How to check if a macro exists in an object file in C?

旧城冷巷雨未停 提交于 2019-12-01 12:02:34
For example, I define a macro: #ifdef VERSION //.... do something #endif How can I check if VERSION exist in my object file or not? I tried to disassemble it with objdump , but found no actual value of my macro VERSION . VERSION is defined in Makefile. Try compiling with -g3 option in gcc . It stores macro information too in the generated ELF file. After this, if you've defined a macro MACRO_NAME just grep for it in the output executable or your object file. For example, $ grep MACRO_NAME a.out # any object file will do instead of a.out Binary file a.out matches Or you can even try, $ strings

How to check if a macro exists in an object file in C?

有些话、适合烂在心里 提交于 2019-12-01 09:50:04
问题 For example, I define a macro: #ifdef VERSION //.... do something #endif How can I check if VERSION exist in my object file or not? I tried to disassemble it with objdump , but found no actual value of my macro VERSION . VERSION is defined in Makefile. 回答1: Try compiling with -g3 option in gcc . It stores macro information too in the generated ELF file. After this, if you've defined a macro MACRO_NAME just grep for it in the output executable or your object file. For example, $ grep MACRO

Ambiguous behaviour of .bss segment in C program

戏子无情 提交于 2019-12-01 04:08:06
I wrote the simple C program (test.c) below:- #include<stdio.h> int main() { return 0; } and executed the follwing to understand size changes in .bss segment. gcc test.c -o test size test The output came out as:- text data bss dec hex filename 1115 552 8 1675 68b test I didn't declare anything globally or of static scope. So please explain why the bss segment size is of 8 bytes. I made the following change:- #include<stdio.h> int x; //declared global variable int main() { return 0; } But to my surprise, the output was same as previous:- text data bss dec hex filename 1115 552 8 1675 68b test

Ambiguous behaviour of .bss segment in C program

点点圈 提交于 2019-12-01 02:05:12
问题 I wrote the simple C program (test.c) below:- #include<stdio.h> int main() { return 0; } and executed the follwing to understand size changes in .bss segment. gcc test.c -o test size test The output came out as:- text data bss dec hex filename 1115 552 8 1675 68b test I didn't declare anything globally or of static scope. So please explain why the bss segment size is of 8 bytes. I made the following change:- #include<stdio.h> int x; //declared global variable int main() { return 0; } But to

Too many sections, assembler error, using boost::spirit

柔情痞子 提交于 2019-11-30 13:12:12
I'm in the progress of writing a compiler for a subset of Java, using boost::spirit , for lexing and parsing. During compilation of the lexer/parser phase, the compiler consumes 1.6GB of RAM ( g++ (GCC) 4.8.1 ), this is not an issue however, as there's plenty of memory on this machine. What is an issue however, is that when the compiler is done, and the assembler starts running ( GNU assembler (GNU Binutils) 2.23.52.20130604 ), it crashes with; as: build/src/ast_generate.o: too many sections (33098) /tmp/cc0ZyvKK.s: Assembler messages: /tmp/cc0ZyvKK.s: Fatal error: can't write build/src/ast

Can I link object files made by one compile to those made by another one?

天涯浪子 提交于 2019-11-30 07:08:23
To be more specific, lets assume that both compilers are on the same platform (OS + instruction set). However, one of the object files was made from a compiler-dependent code. On the other hand - the code is object oriented and respects encapsulation. I need this for a kind of a framework I am making. Target platform is any system where is GCC and Java Virtual Machine. Indeed the framework will be compiled on each platform. The compiler which use the framework user is up to him. Robert S. Barnes You should be able to link them as long as they use the same object file format and target the same

How to put generated files (e.g. object files) into a separate folder when using Qt/qmake?

风格不统一 提交于 2019-11-30 06:45:14
I have a Qt project that uses qmake. To improve clarity and readability, I'd like to keep the source files build system generated files (such as object files) separate. So my first step was putting the source files into a src/ sub directory: myproject/ myproject.pro src/ main.cpp MainWindow.ui ... That way I separated the source files from the build system (*.pro). However, when I then run qmake followed by make , the generated files (object files, etc) are placed into the main project folder: myproject/ myproject.pro Makefile main.o ui_MainWindow.h ... src/ main.cpp MainWindow.ui ... Well, at

Too many sections, assembler error, using boost::spirit

拟墨画扇 提交于 2019-11-29 18:14:03
问题 I'm in the progress of writing a compiler for a subset of Java, using boost::spirit , for lexing and parsing. During compilation of the lexer/parser phase, the compiler consumes 1.6GB of RAM ( g++ (GCC) 4.8.1 ), this is not an issue however, as there's plenty of memory on this machine. What is an issue however, is that when the compiler is done, and the assembler starts running ( GNU assembler (GNU Binutils) 2.23.52.20130604 ), it crashes with; as: build/src/ast_generate.o: too many sections

How to add object files to a project in Qt

倖福魔咒の 提交于 2019-11-29 11:35:55
Currently the linker in one project has problems linking to object files generated by source files in another project. Is there some way to manually add those object files to Qt? Try using the LIBS directive in your *.pro file; LIBS += /path/to/foo.o Building on ismail's answer, if you have a directory with many object files, you don't have to include each one separately. You can just write: LIBS += "../path-to-objs/*.obj" You can also specify different object files to link against for debug and release builds with: Release:LIBS += "../path-to-objs/Release/*.obj" Debug:LIBS += "../path-to-objs