14

During debug in MSVC 2012, I am attempting to call some functions from the Watch window in order to dump data to files. However, I keep getting this error:

Function Matrix::Save has no address, possibly due to compiler optimizations.   

The class Matrix is located in my own external library. A quick check showed that none of the methods in external libraries have addresses and all attempts to call them from Watch return this error, except for those which are defined in the header files. The methods in the main project all have addresses regardless of where they are defined.

Optimization is disabled throughout the solution, of course. Symbols are loaded normally. How do I fix it?

Anton Poznyakovskiy
  • 2,109
  • 1
  • 20
  • 38
  • How is the library linked? Static? Dynamic? If dynamic, how loaded? – doctorlove Dec 04 '14 at 17:27
  • It's linked dynamically. What do you mean by "how loaded"? – Anton Poznyakovskiy Dec 04 '14 at 17:35
  • 1
    @AntonPoznyakovskiy you can have either implicit or explicit loading. If implicit, then the above may work fine. If explicit, then you need to call using the function pointers you've stored. – IdeaHat Dec 04 '14 at 17:37
  • @IdeaHat The library is linked implicitly. Does this mean that it is loaded implicitly, too? – Anton Poznyakovskiy Dec 04 '14 at 17:41
  • I don't think you can explicitly load it implicitly, IYSWIM, but it must be able to find the dll: http://msdn.microsoft.com/en-us/library/d14wsce5.aspx "The operating system must be able to locate the DLL file when it loads the calling executable." – doctorlove Dec 04 '14 at 17:48
  • Actually, I'm not sure I would expect to be able to call any function I liked in the watch window. – doctorlove Dec 04 '14 at 17:49
  • I checked the executable with depends.exe, the path points to the correct library in the output folder of the Debug configuration. Apart that I don't understand why calling some methods in Watch does work and calling other doesn't and that the error message is extremely misleading - are there any other approaches to doing anything advanced during debug except Watch? I would like to avoid hard-coding dumping methods, and the matrices in question are really huge, I cannot extract any meaningful information just by looking at their buffers. – Anton Poznyakovskiy Dec 04 '14 at 17:59
  • Are you building the external lib from source as part of your solution or are you linking against a prebuilt binary? If it's the latter then you have no control over what compiler settings were used to build it – zebrabox Dec 04 '14 at 18:06
  • I am building it from source. Is there anything that I should check in the library project settings? – Anton Poznyakovskiy Dec 04 '14 at 18:09
  • 1
    You could have a configurable hard-coded dump method. Previous watch windows have had problems: http://stackoverflow.com/questions/16844804/trouble-calling-member-function-in-debugger Also, has it loaded the symbols for your dll? If not tell it where they are: http://msdn.microsoft.com/en-us/library/a3694ts5.aspx – doctorlove Dec 05 '14 at 09:51
  • Symbols are loaded, yes. As I posted below, static linking solves the problem. This in only an option as long as one builds the library from the code, of course, but this is my case. As for third-party libraries, your proposal with configurable hard-coded dump is probably the best. I'll wait for a couple of days and see if anyone comes with anything else. – Anton Poznyakovskiy Dec 05 '14 at 10:30
  • 2
    Still no solution? I don't even understand why I'm getting this error in my case. – Violet Giraffe Aug 25 '17 at 08:36

2 Answers2

1

So far, I found a workaround in building the external library statically. With statically linked libraries, the addresses of methods are found. Configuration manager allows keeping dynamic libraries for the Release easily.

Anton Poznyakovskiy
  • 2,109
  • 1
  • 20
  • 38
1

As a simpler woraround, you can call target function(Matrix::Save) at least one time in current code branch. Then it will have an address because it is used.

Brans Ds
  • 4,039
  • 35
  • 64