Reputation: 1093
main.cpp
#include <iostream>
#include <Box2D/Box2D.h>
int main() {
int32 velocityIterations = 6;
int32 positionIterations = 2;
b2Vec2 gravity(0.0f, -10.0f);
b2World world(gravity);
std::cout << "Hello, world!" << std::endl;
}
The error I get:
undefined reference to `b2World::b2World(b2Vec2 const&)'
When I try linking Box2D in CMakeLists.txt:
include_directories(C:/Users/blahblah/CPPLibs)
target_link_libraries(HelloWorld Box2D)
I get:
c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/6.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lBox2D
How I can properly import Box2D to my project?
Upvotes: 0
Views: 2506
Reputation: 26
You can't compile because your linker can't find Box2D source files. You have to add .cpp files manually (which is a poor solution) or create a static library with Box2D source code (e.g. .../Box2D_v2.3.0/Box2D/Box2D). Generated file (e.g. libBox2D.a) add to your project and it should be compiled without any problems.
Upvotes: 1