-1

linking error when building Google test on mac (commandline)

At the bottom, you wrote an edit about finding multiple gmock installations on the same computer messing up the include path for the compiler so it was hitting the old, 1.5 32 bit version instead of the right one.

I installed mine via brew; brew install gmock, and it worked and everything-but I'm having the same problem you did. If you could just tell me how to compile it correctly like you mentioned in your post I'd be pleased enough to go and give you some upvotes, or you could just edit the link, and I would read it (please notify me when you do though).

I have read the instructions on the googlemock google code page and what I downloaded in order to try and get things to build against it. I have searched around a lot, and I can't find anything that comes near as close as what you have talked about.

To explain to you what I'm doing, I wrote a very simple test: http://codepad.org/zxBugY0w

And when I tried to compile it with my locally included information I get: http://pastebin.com/fqEZ6zTq

273K
  • 29,503
  • 10
  • 41
  • 64
Adam Miller
  • 1,756
  • 1
  • 25
  • 44
  • This was my very first question on stackoverflow. The link at the very top, "linking error when..." links to the question I thought that I was replying to, because I meant to ask the original user who posted what is in this. When I clicked his name, at the top right, it said "ask question" – Adam Miller Apr 17 '12 at 17:29

3 Answers3

3

You need to link to gtest and gmock.

In your g++ command, you need to add -L <full path to gtest lib> -L <full path to gmock lib> -lgmock -lgtest.

Fraser
  • 74,704
  • 20
  • 238
  • 215
1

Installing gtest via brew, or at all, isn't a supported configuration. The way gtest is intended to be used is for you to include it with a project and compile both together. Then, you link against your version, which is guaranteed to be compiled with the same settings.

See http://code.google.com/p/googletest/wiki/FAQ#Why_is_it_not_recommended_to_install_a_pre-compiled_copy_of_Goog

Also, note that you're getting a different error from the one in the question you linked to. That person got an error because they accidentally linked against a version that had been compiled with different settings. You're not linking against it at all (though you might see similar errors down the road if you continue with the brew configuration).

sfiera
  • 109
  • 6
  • Please pay no attention to the codepad error, where it says output. Codepad runs the code on their side, and they don't have gmock installed. The error that I got was in the pastebin, please see that. – Adam Miller Apr 17 '12 at 16:38
  • Yes. Your error in the pastebin link is different. His error was due to linking against a non-universal libgtest; yours was not linking against any. Similar error messages, but not the same. – sfiera Apr 17 '12 at 17:41
1

Actually, the problem was that I was not linking with a compiled version of the archive, the libgmock.a

Once I linked, it worked just fine.

Adam Miller
  • 1,756
  • 1
  • 25
  • 44