0

I am using eclipse and keep getting an undefined reference to `__assert_func' error in my c/c++ code.

I am wondering if there is a way to tell what is being defined ( # define **). I can manually go through my files, but I am working with a lot of them and this would take a while. Is there a compiler option or a tool that could list these for me?

Thanks,

Sam

Sam
  • 238
  • 3
  • 14

3 Answers3

3

This is dependent on the compiler. You can read this if you're running GCC.

GCC dump preprocessor defines

Community
  • 1
  • 1
James McDonnell
  • 3,600
  • 1
  • 20
  • 26
1

Undefined reference has nothing to do with #defines. It is a linker error, you may have forgotten to link against a .lib/.a file.

Csq
  • 5,775
  • 6
  • 26
  • 39
  • Well, it could (most like is) an `#define assert(x) assert_func(x, __FILE__, __LINE__)` or some such. – Mats Petersson Jan 20 '13 at 00:17
  • Csq - Thank you I think I may need to include a lib is there a way to find which one I need? google? I am currently linking with -nostdlib – Sam Jan 20 '13 at 00:23
  • 1
    I think asserts are in the standard lib, so try with removing the -nostdlib option – Csq Jan 20 '13 at 00:25
  • It returns many unresolved inclusion errors without -nostdlib. I have to use -nostdlib in order to implement what I am working on. I am including the assert.h file which needs certain defines in order to define the function... I appreciate your time/help – Sam Jan 20 '13 at 00:29
  • 1
    It might not be possible. assert is part of the stdlib. You can write your own assert-like function though. Or ask a new question on SO. – Csq Jan 20 '13 at 00:57
1

You can usually produce the pre-processor output from the compiler - e.g. g++ -E myprog.cpp > myprog.i. I think CL -E does the same thing in Visual Studio, and other compilers tend to have a similar option.

It does sound like your missing function is part of a ASSERT or assert macro.

Mats Petersson
  • 126,704
  • 14
  • 140
  • 227
  • I am including assert.h but I don't think I have the correct defines for the header to define the function – Sam Jan 20 '13 at 00:25
  • 1
    The problem, most likely, is that you are not linking something that you should be linking - but I don't know, as you haven't shown us any code... Try to break down the problem to a small one - it's most likely going to solve your issue. I find putting `#if 0 / #endif` around the content of functions (or outside of functions) helps reduce the amount of code that is "Under suspicion". – Mats Petersson Jan 20 '13 at 00:28
  • Thank you for the tip I will defiantly try that. I am working on implementing a timer class for an ARM processor provided by Atmel and I need to either define the correct thing or find out what I should be linking. I'm sure its a simple issue, I am pretty new to this sort of thing. Thank you again for your help! – Sam Jan 20 '13 at 00:42