{"id":1106,"date":"2022-08-30T15:12:29","date_gmt":"2022-08-30T15:12:29","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/linux-unable-to-link-archives-via-cmake-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:12:29","modified_gmt":"2022-08-30T15:12:29","slug":"linux-unable-to-link-archives-via-cmake-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/linux-unable-to-link-archives-via-cmake-collection-of-common-programming-errors\/","title":{"rendered":"(Linux) Unable to link archives via cmake-Collection of common programming errors"},"content":{"rendered":"<p>Instead of<\/p>\n<pre><code>include_directories(\/usr\/lib)\nlink_libraries(usr\/lib\/libgsl.a usr\/libgslcblas.a)\n<\/code><\/pre>\n<p>try<\/p>\n<pre><code>add_executable (targetName main.cpp class1.cc class2.cc)\ntarget_link_libraries(targetName gsl gslcblas)\n<\/code><\/pre>\n<p>Where <em>targetName<\/em> is the name of the output binary you intend to create. The path <code>\/usr\/lib<\/code> should already be in the default library search path for CMake, so you shouldn&#8217;t have to specify that, but if you did have to specify a custom library path, you would do it like so<\/p>\n<pre><code>link_directories(\/some\/custom\/library\/path)\n<\/code><\/pre>\n<p>The <code>include_directories<\/code> CMake directive is used for adding header search paths, not library search paths&#8230;<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-09 23:28:32. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Instead of include_directories(\/usr\/lib) link_libraries(usr\/lib\/libgsl.a usr\/libgslcblas.a) try add_executable (targetName main.cpp class1.cc class2.cc) target_link_libraries(targetName gsl gslcblas) Where targetName is the name of the output binary you intend to create. The path \/usr\/lib should already be in the default library search path for CMake, so you shouldn&#8217;t have to specify that, but if you did have to specify [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1106","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1106","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1106"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1106\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1106"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}