我尝试使用tiny_obj_loader将</head>
<!-- To use Geocoding from Google Maps V3 you need to link https://maps.googleapis.com/maps/api/js?sensor=false -->
<body>
<div>
<h3> Enter an adress and press the button</h3>
<input id="address" type="text" placeholder="Enter address here" />
<button id="btn">Get LatLong</button>
<div>
<p>Latitude:
<input type="text" id="latitude" readonly />
</p>
<p>Longitude:
<input type="text" id="longitude" readonly />
</p>
</div>
</div>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
/* This showResult function is used as the callback function*/
function showResult(result) {
document.getElementById('latitude').value = result.geometry.location.lat();
document.getElementById('longitude').value = result.geometry.location.lng();
}
function getLatitudeLongitude(callback, address) {
// If adress is not supplied, use default value 'Ferrol, Galicia, Spain'
address = address || 'Ferrol, Galicia, Spain';
// Initialize the Geocoder
geocoder = new google.maps.Geocoder();
if (geocoder) {
geocoder.geocode({
'address': address
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
callback(results[0]);
}
});
}
}
var button = document.getElementById('btn');
button.addEventListener("click", function () {
var address = document.getElementById('address').value;
getLatitudeLongitude(showResult, address)
});
var addressbutton = document.getElementById('address');
addressbutton.addEventListener("keydown", function (e) {
if (e.keyCode === 13) {
var address = document.getElementById('address').value;
getLatitudeLongitude(showResult, address)
}
});
</script>
</body>
</html>
加载到我的程序中。我有以下代码利用这个库:
.obj
然而,这给了我以下链接器错误:
void LoadModel(vector<Shape *> &scene, const char *path) {
attrib_t attrib;
vector<shape_t> shapes;
vector<material_t> materials;
std::string error;
bool ret = tinyobj::LoadObj(
&attrib,
&shapes,
&materials,
&error,
path
);
... // Do stuff with the returned data
函数定义为:
Build/skeleton.o: In function `LoadModel(std::vector<Shape*,
std::allocator<Shape*> >&, char const*)':
skeleton.cpp:(.text+0x3025): undefined reference to `tinyobj::LoadObj(tinyobj::attrib_t*, std::vector<tinyobj::shape_t, std::allocator<tinyobj::shape_t> >*, std::vector<tinyobj::material_t, std::allocator<tinyobj::material_t> >*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, char const*, char const*, bool)'
Makefile:43: recipe for target 'Build' failed
make: *** [Build] Error 1
看起来参数类型对我来说是正确的。
我已将bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
std::vector<material_t> *materials, std::string *err,
const char *filename, const char *mtl_basedir = NULL,
bool triangulate = true);
文件包含在.h
和
skeleton.cpp
#include "tiny_obj_loader.h"
是该文件的名称,该文件位于tiny_obj_loader.h
的同一目录中。
修改 正在使用的Makefile是:
skeleton.cpp
答案 0 :(得分:1)
在实际包含#define TINYOBJLOADER_IMPLEMENTATION
之前,请务必tiny_obj_loader.h
。否则预处理器将已经在该文件上运行,您将无法获得实现。