gcc

C++ Shared Library with Templates: Undefined symbols error

I'm trying to link to a shared library with a template class, but it is giving me "undefined symbols" errors. I've condensed the problem to about 20 lines of code. shared.h template <class Type> class myclass { Type x; public: myclass() { x=0; } void setx(Type y); Type getx(); }; shared.cpp #include "shared.h" template <cla...

C++: Correct order for including both <cstdio> and <stdio.h>?

I need to use system-specific functions, e.g. ftello() (defined in stdio.h as per POSIX standard). I also need to use standard C++ features, e.g. std::sprintf() (defined in cstdio, as per ISO C++ standard). AFAIK, including only <cstdio> doesn't guarantee defining non-standard-C++ stuff, so I guess I have to include both. I've read a lo...

gcc link error occurred

I compiled with gcc gcc -l. 'net-snmp-config --cflags' -fPlC -shared -c -o matsu_object.o tsu_object.c but this error occurred gcc: -lcrypto: Because a link was not completed, the input file of the linker was not used What's wrong? ...

highlight and filter (gcc) compiler messages

Hi, i'm currently refactoring a C-project, throwing about 1000 warnings at me. is there a way to highlight and filter these warnings. (eg make all index warnings red, unused blue, and some other) most likely some ides can do that, but that's no solution for me. ...

Adding leading underscores to assembly symbols with GCC on Win32?

I have a piece of C code that calls a function defined in assembly. By way of example, let's say foo.c contains: int bar(int x); /* returns 2x */ int main(int argc, char *argv[]) { return bar(7); } And bar.s contains the implementation of bar() in x86 assembly: .global bar bar: movl 4(%esp), %eax addl %eax, %eax r...

GCC C++ "Hello World" program -> .exe is 500kb big when compiled on Windows. How can I reduce its size?

Hello, I just recently started learning C++ - I am using nuwen's version of MingW on Windows, using NetBeans as an IDE (I have also MSDN AA Version of MSVC 2008, though I don't use it very often). When compiling this simple program: #include <iostream> using namespace std; int dog, cat, bird, fish; void f(int pet) { cout << "pet i...

how can i print the variable names that are used in a C program

hi, i want to print the variables that are used in my C code .Its a 19KB file,so lot of variables are used in it. i know its not so easy..b'z we donno whre my compiler puts this details..(debug info?..) i am working in gcc ( Redhat (shrike)).. Renjith G ...

GNU C++ error messages

Is there a comprehensive list of error/warning messages for the g++ compiler available online? I'm looking for something similar to the MSDN documentation which describes what each message means and possibly has some sample code which demonstrates the conditions which would cause such an error. I've looked at the GCC online documentati...

Any better alternative to fork() and then execvp(" gcc program.c ") ?

Hi, The following code segment takes more time (5s) when it is run first time and takes less time(250ms) on consecutive runs. Is there any better way to execute gcc. int pid,status; char * argv[] = {"gcc","program.c",NULL}; if(!(pid=fork())){ execvp("gcc",argv); } while(pid!=wait(&status)){ //do nothing } ...

How to know which headers are included without looking at the preprocessed code in GCC?

Hi, I've got some big C programs, and I would like to know when I'm compiling this program, which header files are actually included... The simplest solution would be to print the preprocessed code and look but do you know if there's a way to compile and at the same time showing what header files are included ? ...

VC++ #import directive for GCC/G++

I'm trying to test out a library that provides a VC++ example; however, I use gcc/g++ for all of my projects. Well, the way the VC++ example accesses the library is it uses the #import directive, passing the location of the library DLL, then it does a using namespace LIBRARYNAME, and then it's able to create some undefined type (I'd ass...

inline gcc

Hi, I am trying to implement context switch using gcc for m68k processors. I need to use inline assembly for saving all the registers d0, d1...d7 and a0,...a7. I was wondering if I can use a loop in my inline gcc that would allow me to save these registers instead of write a separate line of code for each register. for eg. move.l %d0,...

Setting GCC 4.2.1 options in Xcode

Howdy, I have a few questions about Xcode and interaction with GCC 4.2.1: It doesn't seem as if Xcode Target Properties inspector exposes all possible GCC options. Is this correct? More specifically, I'm interested in setting the "mfpu" option, as mentioned in the arm_neon.h intrinsics header. Is this possible or supported? Or perhaps...

GCC's extended version of asm

I never thought I'd be posting an assembly question. :-) In GCC, there is an extended version of the asm function. This function can take four parameters: assembly-code, output-list, input-list and overwrite-list. My question is, are the registers in the overwrite-list zeroed out? What happens to the values that were previously in th...

Stack allocation, padding, and alignment

I've been trying to gain a deeper understanding of how compilers generate machine code, and more specifically how GCC deals with the stack. In doing so I've been writing simple C programs, compiling them into assembly and trying my best to understand the outcome. Here's a simple program and the output it generates: asmtest.c: void main...

How to modify options being passed to ld , without recompiling gcc

I'm trying to compile shared library on solaris 2.7 using gcc 3.4.6 and which is linking to a statically linked c .a and .o files. Please note that it is using Sun ld from path "/usr/ccs/bin/ld" At linking time i got a long list of symbols and following error ld: fatal: relocations remain against allocatable but non-writable sections...

Is it possible to turn off support for "and" / "or" boolean operator usage in gcc?

GCC seems to allow "and" / "or" to be used instead of "&&" / "||" in C++ code; however, as I expected, many compilers (notably MSVC 7) do not support this. The fact that GCC allows this has caused some annoyances for us in that we have different developers working on the same code base on multiple platforms and occasionally, these "error...

GCC giving different numerical results with -O0 and -O2

I'm using 4.1.2. Does anyone have any ideas of the best places in my code to look? Experience with common causes? There are some ugly pointer casts (ie, d = (double) (* (float *) p), where p is pointer-to-int) that I'm working on eliminating, but no luck yet. For what it's worth, -O0 is giving the correct answer. Thanks for any help. ...

Error with iPhone Toolchain: libc.dylib unknown flags (type) of section 4 (__TEXT,__dof_magmalloc) in load command 0

Hi all. I seem to be having some issues with building the latest Toolchain for developing for the iPhone. When building llvm-gcc, as per the instructions on the iphone-dev group page, I keep hitting this error: /usr/local/bin/arm-apple-darwin-ld: /usr/local/share/iphone-filesystem/usr/lib/libc.dylib unknown flags (type) of section 4 (__...

Why do I get different results when I dereference a pointer after freeing it?

I've a question about the memory management in C (and GCC 4.3.3 under Debian GNU/Linux). According to the C Programming Language Book by K&R, (chap. 7.8.5), when I free a pointer and then dereference it, is an error. But I've some doubts since I've noted that sometimes, as in the source I've pasted below, the compiler (?) seems to work...