Laya踩坑002_Mac编译后报错file://跨域问题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Laya踩坑002_Mac编译后报错file://跨域问题相关的知识,希望对你有一定的参考价值。

参考技术A 补充更新:

后来发现其实不需要那么麻烦,这个命令更靠谱:

open /Applications/Google\ Chrome.app --args --allow-file-access-from-files

首先是莫名其妙,电脑关机后,项目编译就报错一堆问题。

大意就是不能访问file://的文件(不齐全,我忘了保留截图和报错信息。),报错内容有这么一段: from origin 'null' has been blocked by CORS policy: Cross origin request。(先让我吐槽,然后再说解决方案)

这里真要严重吐槽下Laya的机制:

1. bin目录就不能剥离出去?编译目录和开发目录都不分开?混着来?在bin目录上踩坑真的是恶心透了!!!恶心透了!!!恶心!!!透了!!!

2. 项目内部的文件,从LayaIde里面看,还被换过层级和名字。如果是u3d、cocos的老用户,呵,懵逼去吧~!捋半天,我的天呐~还可以这样玩???(卧槽!)

报错不能获取对应的文件,文件是存在的。

然后查找资料,罗列出来,你们有兴趣自己去深入研究。

http://ask.layabox.com/question/12504 (这里是跟我一样的报错)

https://ask.layabox.com/question/13

https://www.zhihu.com/question/20948649/answer/256887902

前面这3个帖子,只是让你明白,为什么报错。并没有真正的解决方案。

http://ask.layabox.com/question/39289

这个帖子的命令才是真正可以解决问题的。

1. 打开终端

2. 输入下面的命令( Tip:需要替换路径中的 yourname  )

open -n /Applications/Google\ Chrome.app/ --args --disable-web-security  --user-data-dir=/Users/ yourname /MyChromeDevUserData/

注意:

Mac下可使用命令行打开chrome,记住先关闭当前chrome窗口。

网上有些文章--user-data-dir参数后面没有添加文件夹名,是设置不成功的。

这是在mac的根目录在建了一个叫MyChromeDevUserData的文件夹,用于保存关闭安全策略后的用户信息的,名字可以随意取,位置也可以随意放,只要路径是正确的就可以。

发现:

第一次打开chrome有黄色背景色的“--disable-web-security”相关的提示,说明浏览器设置跨域成功。

再次用执行上面的命令行时,不会再有相关提示了,但是还是能跨域的!

Mac(m1) clion编译opencv报错building for macOS-x86_64 but attempting to link with file built for macOS-ar

代码如下:

 

 

具体报错如下:

ignoring file /opt/homebrew/opt/opencv@3/lib/libopencv_dnn.3.4.16.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64

ld: warning: ignoring file /opt/homebrew/opt/opencv@3/lib/libopencv_video.3.4.16.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64

ld: warning: ignoring file /opt/homebrew/opt/opencv@3/lib/libopencv_datasets.3.4.16.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64

ld: warning: ignoring file /opt/homebrew/opt/opencv@3/lib/libopencv_videoio.3.4.16.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64

ld: warning: ignoring file /opt/homebrew/opt/opencv@3/lib/libopencv_objdetect.3.4.16.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64

ld: warning: ignoring file /opt/homebrew/opt/opencv@3/lib/libopencv_imgcodecs.3.4.16.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64

ld: warning: ignoring file /opt/homebrew/opt/opencv@3/lib/libopencv_imgproc.3.4.16.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64

ld: warning: ignoring file /opt/homebrew/opt/opencv@3/lib/libopencv_flann.3.4.16.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64

ld: warning: ignoring file /opt/homebrew/opt/opencv@3/lib/libopencv_calib3d.3.4.16.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64

ld: warning: ignoring file /opt/homebrew/opt/opencv@3/lib/libopencv_photo.3.4.16.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64ld: warning: ignoring file /opt/homebrew/opt/opencv@3/lib/libopencv_features2d.3.4.16.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64

解决办法:

在cmake中添加编译选项:

 

以上是关于Laya踩坑002_Mac编译后报错file://跨域问题的主要内容,如果未能解决你的问题,请参考以下文章

tomcat启动后报错Bad version number in .class file (unable to load class oracle.jdbc.OracleDriver)

错误记录Windows 控制台程序编译报错 ( fatal error C1083: 无法打开包括文件: “afxwin.h”: No such file or directory )

linux安装jdk后报错---bash: /home/java/jdk/jdk1.8.0_301/bin/java: No such file or directory

brew upgrade升级php版本后报错

brew upgrade升级php版本后报错

Mac(m1) clion编译opencv报错building for macOS-x86_64 but attempting to link with file built for macOS-ar