{"id":226,"date":"2008-08-28T18:53:27","date_gmt":"2008-08-28T22:53:27","guid":{"rendered":"http:\/\/mattfife.net\/wordpress\/?p=226"},"modified":"2008-08-28T18:53:27","modified_gmt":"2008-08-28T22:53:27","slug":"when-compiling-glew-or-freeglut-as-a-static-library","status":"publish","type":"post","link":"https:\/\/mattfife.com\/?p=226","title":{"rendered":"When compiling GLEW or freeglut as a static library&#8230;"},"content":{"rendered":"<p>Surprised nobody ran across this yet, but then again, makes sense.<\/p>\n<p>When compiling either the freeglut and GLEW (packages nearly essential of OpenGL graphics development), both have the option to be built as libraries statically or dynamically.\u00a0 When the libraries are built dynamically, you just include the lib in the link line then copy the dll&#8217;s over to your binary folder.\u00a0 But when compiled statically, you need to specify GLEW_STATIC and FREEGLUT_STATIC symbols as compile-time defines when compiling the libraries (and be free of dll hell).<\/p>\n<p>The tricky part is when you include those two libraries in <em>another <\/em>library and then try to compile that combination into a binary.\u00a0 In the case of freeglut, the linker will complain that it can&#8217;t find &#8220;freeglut.lib&#8221;.\u00a0 Which is strange because freeglut static compiles into a library named &#8220;freeglut_static.lib&#8221; and only the dll version compiles into &#8220;freeglut.lib&#8221;.\u00a0\u00a0 Hmmm, why is freeglut looking for the wrong lib?\u00a0 Well, freeglut_std.h line 53 holds the key.\u00a0\u00a0 If FREEGLUT_STATIC is defined, then there is a pragma to include &#8220;freeglut_static.lib&#8221; otherwise the pragma points to &#8220;freeglut.lib&#8221;.\u00a0 So, you need to include the -D FREEGLUT_STATIC in the link line of the final <em>executable&#8217;s<\/em> link line as well.<\/p>\n<p>GLEW also has this problem, but if you forget the -D GLEW_STATIC in the link line of the executable, you&#8217;ll get errors about unresolved externals.<\/p>\n<p>And there you have it.<\/p>\n<p>(update: you must also put\u00a0 GLEW_STATIC and FREEGLUT_STATIC in the link lines of the intermediate libraries as well.\u00a0 The chain of libraries from freeglut and glew ALL need to have that compile parameter specified or you&#8217;ll get the same errors).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Surprised nobody ran across this yet, but then again, makes sense. When compiling either the freeglut and GLEW (packages nearly essential of OpenGL graphics development), both have the option to be built as libraries statically or dynamically.\u00a0 When the libraries are built dynamically, you just include the lib in the link line then copy the dll&#8217;s over to your binary folder.\u00a0 But when compiled statically, you need to specify GLEW_STATIC and FREEGLUT_STATIC symbols as compile-time defines when compiling the libraries&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/mattfife.com\/?p=226\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-226","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4WECr-3E","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/mattfife.com\/index.php?rest_route=\/wp\/v2\/posts\/226","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mattfife.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mattfife.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mattfife.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mattfife.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=226"}],"version-history":[{"count":0,"href":"https:\/\/mattfife.com\/index.php?rest_route=\/wp\/v2\/posts\/226\/revisions"}],"wp:attachment":[{"href":"https:\/\/mattfife.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mattfife.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mattfife.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}