简体   繁体   English

在C ++源文件中定义链接选项

[英]Define linking options in C++ source file

I'm in a very weird position where I am not able to modify the makefile, just the source code, but need to link other libraries. 我处于一个非常奇怪的位置,在这里我无法修改makefile,只能修改源代码,但是需要链接其他库。 Is there any way to specify a linking option (eg -lcuda) in the source file or somehow get it to compile? 是否可以在源文件中指定链接选项(例如-lcuda)或以某种方式进行编译? I'm using GCC 4.8. 我正在使用GCC 4.8。 Thanks! 谢谢!

You may try to use LDFLAGS environment variable to add necessary options. 您可以尝试使用LDFLAGS环境变量添加必要的选项。

For example: 例如:

$ LDFLAGS=-lcuda make

Reviving this to explain the problem better and the solution I came up with. 复活这个以更好地解释问题和我想出的解决方案。 This was for an assignment for a CS class where we needed to optimize various math kernels and algorithms as much as possible. 这是针对CS类的作业,我们需要尽可能地优化各种数学内核和算法。 The rules were pretty much "anything goes" as long as everything was contained in the source file. 只要所有内容都包含在源文件中,规则几乎就是“一切”。 You couldn't edit anything else including the makefile, environment, or other source files. 您无法编辑其他任何内容,包括makefile,环境或其他源文件。

My solution was to make and compile my own, separate, executable that used CUDA and include the binary in my source file. 我的解决方案是制作和编译我自己的,单独的,使用CUDA的可执行文件,并将二进制文件包含在我的源文件中。 The source file would execute the binary, then communicate with it through pipes. 源文件将执行二进制文件,然后通过管道与其进行通信。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM